mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-02 12:47:41 +02:00
Merge branch 'dev' of github.com:laurent22/joplin into dev
This commit is contained in:
commit
bbae1aef28
@ -16,6 +16,7 @@ import com.facebook.soloader.SoLoader;
|
||||
|
||||
import net.cozic.joplin.share.SharePackage;
|
||||
import net.cozic.joplin.ssl.SslPackage;
|
||||
import net.cozic.joplin.textinput.TextInputPackage;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -44,6 +45,7 @@ public class MainApplication extends Application implements ReactApplication {
|
||||
// Packages that cannot be autolinked yet can be added manually here, for example:
|
||||
packages.add(new SharePackage());
|
||||
packages.add(new SslPackage());
|
||||
packages.add(new TextInputPackage());
|
||||
return packages;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,63 @@
|
||||
package net.cozic.joplin.textinput;
|
||||
|
||||
import android.text.Selection;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.react.views.textinput.ReactEditText;
|
||||
import com.facebook.react.views.textinput.ReactTextInputManager;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class provides a workaround for <a href="https://github.com/facebook/react-native/issues/29911">
|
||||
* https://github.com/facebook/react-native/issues/29911</a>
|
||||
*
|
||||
* The reason the editor is scrolled seems to be due to this block in
|
||||
* <pre>android.widget.Editor#onFocusChanged:</pre>
|
||||
*
|
||||
* <pre>
|
||||
* // The DecorView does not have focus when the 'Done' ExtractEditText button is
|
||||
* // pressed. Since it is the ViewAncestor's mView, it requests focus before
|
||||
* // ExtractEditText clears focus, which gives focus to the ExtractEditText.
|
||||
* // This special case ensure that we keep current selection in that case.
|
||||
* // It would be better to know why the DecorView does not have focus at that time.
|
||||
* if (((mTextView.isInExtractedMode()) || mSelectionMoved)
|
||||
* && selStart >= 0 && selEnd >= 0) {
|
||||
* Selection.setSelection((Spannable)mTextView.getText(),selStart,selEnd);
|
||||
* }
|
||||
* </pre>
|
||||
* When using native Android TextView mSelectionMoved is false so this block is skipped,
|
||||
* with RN however it's true and this is where the scrolling comes from.
|
||||
*
|
||||
* The below workaround resets the selection before a focus event is passed on to the native component.
|
||||
* This way when the above condition is reached <pre>selStart == selEnd == -1</pre> and no scrolling
|
||||
* happens.
|
||||
*/
|
||||
public class TextInputPackage implements com.facebook.react.ReactPackage {
|
||||
@NonNull
|
||||
@Override
|
||||
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
||||
return Collections.singletonList(new ReactTextInputManager() {
|
||||
@Override
|
||||
public void receiveCommand(ReactEditText reactEditText, String commandId, @Nullable ReadableArray args) {
|
||||
if ("focus".equals(commandId) || "focusTextInput".equals(commandId)) {
|
||||
Selection.removeSelection(reactEditText.getText());
|
||||
}
|
||||
super.receiveCommand(reactEditText, commandId, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user