Skip to content

Commit

Permalink
fix: onContentSizeChanged on mount
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Aug 14, 2024
1 parent 9819f37 commit d32adf6
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java
index 26dc163..4dd8a47 100644
--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java
+++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java
@@ -18,6 +18,8 @@ import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
+import android.os.Handler;
+import android.os.Looper;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
@@ -1231,12 +1233,14 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
mPreviousContentHeight = contentHeight;
mPreviousContentWidth = contentWidth;

- mEventDispatcher.dispatchEvent(
- new ReactContentSizeChangedEvent(
- mSurfaceId,
- mEditText.getId(),
- PixelUtil.toDIPFromPixel(contentWidth),
- PixelUtil.toDIPFromPixel(contentHeight)));
+ // fixes `onContentSizeChanged` not being fired in JS on mount
+ Handler handler = new Handler(Looper.getMainLooper());
+ handler.postDelayed(() -> mEventDispatcher.dispatchEvent(
+ new ReactContentSizeChangedEvent(
+ mSurfaceId,
+ mEditText.getId(),
+ PixelUtil.toDIPFromPixel(mPreviousContentWidth),
+ PixelUtil.toDIPFromPixel(mPreviousContentHeight))), 1);
}
}
}

0 comments on commit d32adf6

Please sign in to comment.