mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-29 12:55:21 +08:00
Fix issue with soft keyboard not showing from time to time on Android (#152)
This commit is contained in:
committed by
GitHub
parent
de9bfc3021
commit
6508386424
@@ -1,16 +1,14 @@
|
|||||||
package com.swmansion.rnscreens;
|
package com.swmansion.rnscreens;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.Animation;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.view.animation.AnimationUtils;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
@@ -63,6 +61,22 @@ public class Screen extends ViewGroup implements ReactPointerEventsView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static OnAttachStateChangeListener sShowSoftKeyboardOnAttach = new OnAttachStateChangeListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewAttachedToWindow(View view) {
|
||||||
|
InputMethodManager inputMethodManager =
|
||||||
|
(InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
inputMethodManager.showSoftInput(view, 0);
|
||||||
|
view.removeOnAttachStateChangeListener(sShowSoftKeyboardOnAttach);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewDetachedFromWindow(View view) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private final Fragment mFragment;
|
private final Fragment mFragment;
|
||||||
private final EventDispatcher mEventDispatcher;
|
private final EventDispatcher mEventDispatcher;
|
||||||
private @Nullable ScreenContainer mContainer;
|
private @Nullable ScreenContainer mContainer;
|
||||||
@@ -88,6 +102,27 @@ public class Screen extends ViewGroup implements ReactPointerEventsView {
|
|||||||
clearDisappearingChildren();
|
clearDisappearingChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
// This method implements a workaround for RN's autoFocus functionality. Because of the way
|
||||||
|
// autoFocus is implemented it sometimes gets triggered before native text view is mounted. As
|
||||||
|
// a result Android ignores calls for opening soft keyboard and here we trigger it manually
|
||||||
|
// again after the screen is attached.
|
||||||
|
View view = getFocusedChild();
|
||||||
|
if (view != null) {
|
||||||
|
while (view instanceof ViewGroup) {
|
||||||
|
view = ((ViewGroup) view).getFocusedChild();
|
||||||
|
}
|
||||||
|
if (view instanceof TextView) {
|
||||||
|
TextView textView = (TextView) view;
|
||||||
|
if (textView.getShowSoftInputOnFocus()) {
|
||||||
|
textView.addOnAttachStateChangeListener(sShowSoftKeyboardOnAttach);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* While transitioning this property allows to optimize rendering behavior on Android and provide
|
* While transitioning this property allows to optimize rendering behavior on Android and provide
|
||||||
* a correct blending options for the animated screen. It is turned on automatically by the container
|
* a correct blending options for the animated screen. It is turned on automatically by the container
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static com.swmansion.rnscreens.Screen.StackAnimation.*;
|
|
||||||
|
|
||||||
public class ScreenStack extends ScreenContainer {
|
public class ScreenStack extends ScreenContainer {
|
||||||
|
|
||||||
private final ArrayList<Screen> mStack = new ArrayList<>();
|
private final ArrayList<Screen> mStack = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user