Skip to content

Instantly share code, notes, and snippets.

@Kudo
Created December 9, 2024 15:19
Show Gist options
  • Save Kudo/ffc4d7bcac965e3f647ca19543d2f139 to your computer and use it in GitHub Desktop.
Save Kudo/ffc4d7bcac965e3f647ca19543d2f139 to your computer and use it in GitHub Desktop.
patch to fix react-native #47926
#!/usr/bin/bash
# Add react-native patches
mkdir -p patches
cat > patches/react-native+0.76.3.patch << EOF
diff --git a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
index 860118d..141978c 100644
--- a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
+++ b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
@@ -95,7 +95,9 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
}
const keyboardY =
- keyboardFrame.screenY - (this.props.keyboardVerticalOffset ?? 0);
+ keyboardFrame.height > 0
+ ? keyboardFrame.screenY - (this.props.keyboardVerticalOffset ?? 0)
+ : keyboardFrame.screenY;
if (this.props.behavior === 'height') {
return Math.max(
@@ -162,7 +164,9 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
}
const {duration, easing, endCoordinates} = this._keyboardEvent;
- const height = await this._relativeKeyboardHeight(endCoordinates);
+ const height = Math.ceil(
+ await this._relativeKeyboardHeight(endCoordinates),
+ );
if (this._bottom === height) {
return;
diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java
index 90c638e..e7a97f3 100644
--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java
+++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java
@@ -870,36 +870,27 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
if (keyboardIsVisible != mKeyboardIsVisible) {
mKeyboardIsVisible = keyboardIsVisible;
- if (keyboardIsVisible) {
- Insets imeInsets = rootInsets.getInsets(WindowInsets.Type.ime());
- Insets barInsets = rootInsets.getInsets(WindowInsets.Type.systemBars());
- int height = imeInsets.bottom - barInsets.bottom;
-
- ViewGroup.LayoutParams rootLayoutParams = getRootView().getLayoutParams();
- Assertions.assertCondition(rootLayoutParams instanceof WindowManager.LayoutParams);
-
- int softInputMode = ((WindowManager.LayoutParams) rootLayoutParams).softInputMode;
- int screenY =
- softInputMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING
- ? mVisibleViewArea.bottom - height
- : mVisibleViewArea.bottom;
-
- sendEvent(
- "keyboardDidShow",
- createKeyboardEventPayload(
- PixelUtil.toDIPFromPixel(screenY),
- PixelUtil.toDIPFromPixel(mVisibleViewArea.left),
- PixelUtil.toDIPFromPixel(mVisibleViewArea.width()),
- PixelUtil.toDIPFromPixel(height)));
- } else {
- sendEvent(
- "keyboardDidHide",
- createKeyboardEventPayload(
- PixelUtil.toDIPFromPixel(mVisibleViewArea.height()),
- 0,
- PixelUtil.toDIPFromPixel(mVisibleViewArea.width()),
- 0));
- }
+ Insets imeInsets = rootInsets.getInsets(WindowInsets.Type.ime());
+ Insets barInsets = rootInsets.getInsets(WindowInsets.Type.systemBars());
+ int height = imeInsets.bottom - barInsets.bottom;
+
+ ViewGroup.LayoutParams rootLayoutParams = getRootView().getLayoutParams();
+ Assertions.assertCondition(rootLayoutParams instanceof WindowManager.LayoutParams);
+
+ int softInputMode = ((WindowManager.LayoutParams) rootLayoutParams).softInputMode;
+ int screenY =
+ softInputMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING
+ ? mVisibleViewArea.bottom - height
+ : mVisibleViewArea.bottom;
+
+ String eventName = keyboardIsVisible ? "keyboardDidShow" : "keyboardDidHide";
+ sendEvent(
+ eventName,
+ createKeyboardEventPayload(
+ PixelUtil.toDIPFromPixel(screenY),
+ PixelUtil.toDIPFromPixel(mVisibleViewArea.left),
+ PixelUtil.toDIPFromPixel(mVisibleViewArea.width()),
+ PixelUtil.toDIPFromPixel(Math.max(height, 0))));
}
}
@@ -944,8 +935,8 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
sendEvent(
"keyboardDidHide",
createKeyboardEventPayload(
- PixelUtil.toDIPFromPixel(mVisibleViewArea.height()),
- 0,
+ PixelUtil.toDIPFromPixel(mVisibleViewArea.bottom),
+ PixelUtil.toDIPFromPixel(mVisibleViewArea.left),
PixelUtil.toDIPFromPixel(mVisibleViewArea.width()),
0));
}
EOF
npx expo install patch-package postinstall-postinstall
jq '.scripts.postinstall = "patch-package"' package.json > package.json.tmp && mv package.json.tmp package.json
npx patch-package
# Add config-plugin to build ReactAndroid from source
mkdir -p plugins
cat > plugins/withAndroidBuildFromSource.js << EOF
const { withSettingsGradle } = require('expo/config-plugins');
module.exports = function withAndroidBuildFromSource(config) {
return withSettingsGradle(config, async (config) => {
const contentToAdd = \`
includeBuild('../node_modules/react-native') {
dependencySubstitution {
substitute(module("com.facebook.react:react-android")).using(project(":packages:react-native:ReactAndroid"))
substitute(module("com.facebook.react:react-native")).using(project(":packages:react-native:ReactAndroid"))
substitute(module("com.facebook.react:hermes-android")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
substitute(module("com.facebook.react:hermes-engine")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
}
}
\`;
if (!config.modResults.contents.includes(contentToAdd)) {
config.modResults.contents = config.modResults.contents + contentToAdd;
}
return config;
});
};
EOF
jq '.expo.plugins += ["./plugins/withAndroidBuildFromSource"]' app.json > app.json.tmp && mv app.json.tmp app.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment