From 34b2290919d77ad4877ab623766e27fc2349b727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Mon, 26 Oct 2026 10:48:52 +0100 Subject: [PATCH 01/28] feat: add onScroll event to web --- src/types.ts | 11 +++++++++++ src/web/EnrichedTextInput.tsx | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/types.ts b/src/types.ts index d478b123c..570cf0b1a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -427,10 +427,18 @@ export interface OnSubmitEditing { text: string; } +export interface OnScrollEvent { + contentOffset: { + x: number; + y: number; + }; +} + // Component types export type FocusEvent = NativeSyntheticEvent; export type BlurEvent = NativeSyntheticEvent; +export type ScrollEvent = NativeSyntheticEvent; /** * Imperative handle exposed via `ref` on ``. @@ -784,6 +792,9 @@ export interface EnrichedTextInputProps extends Omit { */ onPasteImages?: (e: NativeSyntheticEvent) => void; + /** Called when the user scrolls the editor content. */ + onScroll?: (e: ScrollEvent) => void; + /** * Additional items to inject into the native text-selection context menu * (the popover that appears when the user long-presses selected text). diff --git a/src/web/EnrichedTextInput.tsx b/src/web/EnrichedTextInput.tsx index 1002b647c..1edef2f74 100644 --- a/src/web/EnrichedTextInput.tsx +++ b/src/web/EnrichedTextInput.tsx @@ -123,6 +123,7 @@ export const EnrichedTextInput = ({ onLinkDetected, onLinkPress, onSubmitEditing, + onScroll, returnKeyType, submitBehavior, onPasteImages, @@ -195,6 +196,15 @@ export const EnrichedTextInput = ({ return false; }; + const handleScroll = (event: React.UIEvent) => { + const element = event.currentTarget; + onScroll?.( + adaptWebToNativeEvent(event, { + contentOffset: { x: element.scrollLeft, y: element.scrollTop }, + }) + ); + }; + const { handleLinkPress, handleLinkMouseDown } = useLinkPress( () => onLinkPressRef.current ); @@ -479,6 +489,7 @@ export const EnrichedTextInput = ({ } style={finalStyle} data-placeholder={placeholder} + onScroll={handleScroll} /> ); From beb0696dde86ea078d5dd6a9de3023a9650f0f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Mon, 26 Oct 2026 12:21:36 +0100 Subject: [PATCH 02/28] feat: add scroll event throtling on web --- src/utils/EnrichedTextInputDefaultProps.ts | 1 + src/web/EnrichedTextInput.tsx | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/utils/EnrichedTextInputDefaultProps.ts b/src/utils/EnrichedTextInputDefaultProps.ts index 0cf2b3170..bae679ff4 100644 --- a/src/utils/EnrichedTextInputDefaultProps.ts +++ b/src/utils/EnrichedTextInputDefaultProps.ts @@ -13,4 +13,5 @@ export const ENRICHED_TEXT_INPUT_DEFAULT_PROPS = { { trigger: '- ', style: 'unordered_list' }, { trigger: '1. ', style: 'ordered_list' }, ] as TextShortcut[], + scrollEventThrottle: 16, } as const; diff --git a/src/web/EnrichedTextInput.tsx b/src/web/EnrichedTextInput.tsx index 1edef2f74..209494fbe 100644 --- a/src/web/EnrichedTextInput.tsx +++ b/src/web/EnrichedTextInput.tsx @@ -100,6 +100,14 @@ function runFocused( runSafelyInEditor(editor, (e) => apply(e.chain().focus()).run()); } +function shouldEmitScrollEvent( + lastTick: number, + eventThrottle: number +): boolean { + const timeSinceLastTick = Date.now() - lastTick; + return eventThrottle > 0 && timeSinceLastTick >= eventThrottle; +} + export const EnrichedTextInput = ({ ref, defaultValue, @@ -173,6 +181,9 @@ export const EnrichedTextInput = ({ const sanitizationConfigRef = useStableRef(sanitizationConfig); const mentionCallbacksRef = useStableRef(mentionCallbacks); const textShortcutsRef = useStableRef(textShortcuts); + const scrollState = useStableRef({ + scrollLastTick: 0, + }); const editorInstanceRef = useRef(null); @@ -197,6 +208,16 @@ export const EnrichedTextInput = ({ }; const handleScroll = (event: React.UIEvent) => { + if ( + !shouldEmitScrollEvent( + scrollState.current.scrollLastTick, + ENRICHED_TEXT_INPUT_DEFAULT_PROPS.scrollEventThrottle + ) + ) { + return; + } + scrollState.current.scrollLastTick = Date.now(); + const element = event.currentTarget; onScroll?.( adaptWebToNativeEvent(event, { From da69d5f8ff6a105219dad76d9b15c82ed0e17ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Mon, 26 Oct 2026 12:29:58 +0100 Subject: [PATCH 03/28] refactor: changed the throttle ref to a number not an object --- src/web/EnrichedTextInput.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/web/EnrichedTextInput.tsx b/src/web/EnrichedTextInput.tsx index 209494fbe..4cff9c76b 100644 --- a/src/web/EnrichedTextInput.tsx +++ b/src/web/EnrichedTextInput.tsx @@ -181,11 +181,9 @@ export const EnrichedTextInput = ({ const sanitizationConfigRef = useStableRef(sanitizationConfig); const mentionCallbacksRef = useStableRef(mentionCallbacks); const textShortcutsRef = useStableRef(textShortcuts); - const scrollState = useStableRef({ - scrollLastTick: 0, - }); const editorInstanceRef = useRef(null); + const scrollLastTickRef = useRef(0); const handleKeyDown = (doc: Node, event: KeyboardEvent): boolean => { onKeyPressRef.current?.(adaptWebToNativeEvent(event, { key: event.key })); @@ -210,13 +208,13 @@ export const EnrichedTextInput = ({ const handleScroll = (event: React.UIEvent) => { if ( !shouldEmitScrollEvent( - scrollState.current.scrollLastTick, + scrollLastTickRef.current, ENRICHED_TEXT_INPUT_DEFAULT_PROPS.scrollEventThrottle ) ) { return; } - scrollState.current.scrollLastTick = Date.now(); + scrollLastTickRef.current = Date.now(); const element = event.currentTarget; onScroll?.( From a29b77f52085289a772822bb2facb837ce9beb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Tue, 27 Oct 2026 14:48:09 +0100 Subject: [PATCH 04/28] feat: add onScroll on ios --- apps/example/ios/Podfile.lock | 162 +++++++++---------- apps/example/src/screens/DevScreen.tsx | 1 + apps/example/src/screens/TestScreen.tsx | 3 + ios/EnrichedTextInputView.mm | 29 ++++ src/native/EnrichedTextInput.tsx | 4 + src/spec/EnrichedTextInputNativeComponent.ts | 9 ++ src/types.ts | 6 + src/web/EnrichedTextInput.tsx | 6 +- 8 files changed, 135 insertions(+), 85 deletions(-) diff --git a/apps/example/ios/Podfile.lock b/apps/example/ios/Podfile.lock index ab66e8931..13261c5ea 100644 --- a/apps/example/ios/Podfile.lock +++ b/apps/example/ios/Podfile.lock @@ -2063,95 +2063,95 @@ EXTERNAL SOURCES: :path: build/rncore-facades/Yoga SPEC CHECKSUMS: - boost: 2a9d6e1d9873337543f08d9dbc007b288f4e113b - DoubleConversion: e85e4faac763226bfd1cc4c6a98d8355149b27a5 - fast_float: 908e5ee35999f3d91af4b962ac951acac591866c - FBLazyVector: 953381a667ad5f4119b929026e53c4f3aa0da7e7 - fmt: c7776a2a4b1d7ce88b809a1e4d1f7add0f2369df - glog: b4427c3119645da795ff09985ba9da909c940c96 + boost: 8502bfdc46e2804408af2e163049ece181009af4 + DoubleConversion: 501a575c40c0b50c89685762dd3e415e6bb26fb0 + fast_float: 7c925d1cebf8328d4018d061f49377e9f887e3b4 + FBLazyVector: fdebac2dfe9c53bca49f8218fbdf1e24e36c8be0 + fmt: ba0886e864ebb21d14c98b2e12e164b8002f5b93 + glog: 3cf7cb46f743c4bc758ae3e6d9c15bd1b4cfd6d4 hermes-engine: a1158910bb7e300b9e3d2f1e2d433f817ec1a4b5 - RCT-Folly: d173e541eeb78cad5c81011c1bbf62d5b86b9778 - RCTDeprecation: b5015bad0dc536eff092b252e8cdcf7903448e03 - RCTRequired: 1f568a6519677ef482387250f5a098a9ec5dba57 + RCT-Folly: 82921e585c0400eda46fac1068297aa9dfb035e4 + RCTDeprecation: e134f2a2c096a6450f5fcbbe949531f913a2ff04 + RCTRequired: f1a68295837ee8f91e112ed1b5694d12e7ff1784 RCTSwiftUI: 4b21ec5b1f86acb9c96bb429100ad88d4023ed76 - RCTSwiftUIWrapper: 118a21dd01e8000e0583f5f5660a815975aa9cf5 + RCTSwiftUIWrapper: 68bd9fac4e710259cb2b202472adc5f4d113e872 RCTTypeSafety: 77078a9c26030dd84a6bdae74ed900159f89a098 React: 8dafd0ef058191e9e7238cfa6b3deaa24398e5dd - React-bridging: af8fb3f4aebda43f116b69d08384bc3058940b24 - React-callinvoker: 990aad7c20625b59200be77eea7f21f80280a9db - React-Core: f9dd5e5a1c462c8bed235c305c2e2309dfc105f8 - React-Core-prebuilt: 9e4e8e87cae574b60a941e4ce6b621911e4d5cf3 - React-CoreModules: fe68e8743f1586a0557fe8d754b34c0c8d8c5b74 - React-cxxreact: 4a05b5c0a8d75d56816529edbc02beab1606e216 + React-bridging: 658efeb1b4704d5f60ea2fb6e8ca826ab0ae3234 + React-callinvoker: 4e40c208c1ea46686c084a7c23da6a65cbb99482 + React-Core: a831be15fcea0e345a24cb10d6cc0b87e9913d03 + React-Core-prebuilt: 0fd2555a42f40e7770ced1c7dfc5ee1dbfe041cd + React-CoreModules: a86fbe698fd817c17b3936832dc1106a130c4694 + React-cxxreact: 48ca56bd4f26de869478a803a5544b101a57cde6 React-cxxstableapi: f35502b4c542a0d44031b42f91c4ca813d267e16 - React-debug: 225d5d56d096312e1a744b6839a2ad929258b2dd - React-defaultsnativemodule: e88fa0070d99850f11ca368be23f5bd960f9dcdc - React-domnativemodule: 45f2a0aac0866d0da969125eb0c67cecea189180 - React-Fabric: 15c7c42e5faef29d76e398824556f7cf9cc04d35 - React-FabricComponents: 3025339f15ac4715de8a2619a3146c842035bd26 - React-FabricImage: cc00f781af90a934f35c1050466b18fddd86d4cd - React-featureflags: 548879104928d75f937bdea454ce0cb89673878a - React-featureflagsnativemodule: 30eed289f12d51ba7a9744545d783fcfc76b71fd - React-graphics: 69c2173051f1cfa5daf370d5e2c2e1783a621129 - React-hermes: 42d3b1d6de9857595c256eb8996bb106ed40e0ed - React-idlecallbacksnativemodule: 6cc2ba62bb034708f6dd90e61a65a1eb7d3e3bcf - React-ImageManager: 2cdaadea57d74052a6548155e157e6b10e813bd2 - React-intersectionobservernativemodule: 0bcd8856f0eabff39b8f3ba0203b87b0d1d3fca2 - React-jserrorhandler: f10ca6b509737a3f872eb6aafe97fd4394ce33d9 - React-jsi: f85e93f9b8d40804731d90b49165b2a9dd842d81 - React-jsiexecutor: 46ef706cd6a6078ded3338b45bb954e7895505bc - React-jsinspector: 378fea230352b1c00d497283b24df340743627cd - React-jsinspectorcdp: b48d8a2931f505fb71213facf4668db6b0d714e3 - React-jsinspectornetwork: 24f58d9def362e363b3aa7d3f65f1bbdd340396b - React-jsinspectortracing: 31f12c0953ecf1bc98872398cb15e6907cc89aa7 - React-jsitooling: b81a8421cd105cfa04d5575192dee261f719c243 - React-jsitracing: d502415ab958446c09c164a0378d62a61be2b438 - React-logger: 08a3fb49d43447115f6a094cbbe4aaba308d4ed0 - React-Mapbuffer: ebfc6ddeba62b89b3118ab9206e83b8ad1419123 - React-microtasksnativemodule: b8478c203a5d65f5729a5d72564b5625306246d2 - React-mutationobservernativemodule: 4b42b9a136d149799864720e5201a9ce190d2bef - react-native-image-picker: f166d85a3fbdc52ac9ed01062250140c44ba247b - React-NativeModulesApple: cb7ad2bcca44bc4e65eff580b7a7c2d2c6914fa0 - React-networking: 71c78b3c3afca071b8534b10ee501177b7938c9b - React-oscompat: 15c32b3f1e17618e60658411167c2746857fbba5 - React-perflogger: 7997b8eaa3d953be049f3897f9796a1c1eaefdc7 - React-performancecdpmetrics: 1f1cb4196ce97621504a11cd1a106fcd76660b6f - React-performancetimeline: 60f947e3384c00396e71bbb9548e112a94eb13a8 + React-debug: 238e15d17dfded9419a6d739d4c8b60968bad02e + React-defaultsnativemodule: c028edc7e48914344b823931aec1cc4ffabe631e + React-domnativemodule: b09770fc69f5ce5759de98f8065cab900b6d87d6 + React-Fabric: a157c978603fa2796f349f3a27d17861e55804c5 + React-FabricComponents: c7c58a1deea5db215e9d5a2aec890e208d5d5075 + React-FabricImage: 234346bf5a3ef918f3873e845b57b93b2b1f31c0 + React-featureflags: a00ac5c38e63d5f86de895ca923f07f5ff76de66 + React-featureflagsnativemodule: 6b93ba0aef46757b9d54166475abc5e4fa80e70d + React-graphics: 634bc2e5884b4a29f56aa8aef719e03171a23f6b + React-hermes: 9ce7aaf6784709e196ac51bfd89dd6c551e3fb4c + React-idlecallbacksnativemodule: e02e194086278377ced48b7fd7816b6c925b9e7e + React-ImageManager: 452d4b3587f21d3384868e2abaab7c0a952b1d1c + React-intersectionobservernativemodule: 3ddbc206bc95c086f1df6eea04aa617ae02627d2 + React-jserrorhandler: a0d842e1f74cc10e597fde2a6447860483df2b13 + React-jsi: 489de0620905b88a17ccb0ac2328046af43e7ebd + React-jsiexecutor: f0e2ae6d98b587d3505ebde246599ee3ad97cee1 + React-jsinspector: 515bf11caeda5df444f39aec63e377ef77ad7696 + React-jsinspectorcdp: be9ac71a77880a6fcc95375e7e61a79e152a3203 + React-jsinspectornetwork: a4bc1475897a2301d114d7a8605af3e8760f9e52 + React-jsinspectortracing: 7d35952c944dc337d1a4167605c1338108880219 + React-jsitooling: 1886dc5058e9feded2136b0d9ba5c189c6af5faa + React-jsitracing: 76b58feee3fb0539c8967e5b9de1a40ad8014f09 + React-logger: 3d2b406a780fed50ad0bbd07452b373c2a515308 + React-Mapbuffer: a2dae4f2cb335ebb97f2240494d0c2bab84cd339 + React-microtasksnativemodule: 8b3aaa5f3b907ecf071b105589868d9f027a448d + React-mutationobservernativemodule: 11d77d3f7360578f07847843544ada23cc473049 + react-native-image-picker: dc809b800c612d43b6508095cca505c32cf9d3c8 + React-NativeModulesApple: 52f3def085f129de1307e3eb78e26729ff70f421 + React-networking: 1e6441349ac72bfd4f7a79c300c3dd76993a7058 + React-oscompat: e64123dd8199f9e99cede19fa542c3da3445481e + React-perflogger: f1466e0f46ce706aef73a559337eca85f51a40b7 + React-performancecdpmetrics: f238752e99eb7c69c782020827bff38a4b1b2ef2 + React-performancetimeline: f1b216fa02200c859cd18ef345d4230cd712137a React-RCTActionSheet: 81662769b1f576e9c2e074deb41d6b83d1c7e29f - React-RCTAnimatedModuleProvider: e71da181d50d3d19ab5fa24ace7b9cef67453ba2 - React-RCTAnimation: d900133c5fd04ea66576c0221e369be255aa27c8 - React-RCTAppDelegate: 8190863c58350373cc2929ef8b22faeaeaa3fa5f - React-RCTBlob: 7d6a4709dcd74281b6d0e8ccd10e2847f3c882fb - React-RCTFabric: 9a34936cb16f86e90fc4e5911ca068c43db78c0f - React-RCTFBReactNativeSpec: d9f8c284e5d965bd7a2a718e06b076204c383394 - React-RCTImage: 5d62b5686350935a52e0bc5c961339476a0da0d9 - React-RCTLinking: 5a019526644083957085610a3399094fd8d0819e - React-RCTNetwork: a7b8711829339321eb368aa1708f35b55a9e5e82 - React-RCTRuntime: a745878bbad8ba81420e95030b317c2116a3ae33 - React-RCTSettings: 9ac026a882b58f12c8ddaff02df4e60988439310 - React-RCTText: f9bf7738a96fc25968857f4c1c4d5c4257874b41 - React-RCTVibration: 400e227a70dfdf7c0924cd990c54c57fbcb194d1 + React-RCTAnimatedModuleProvider: a9829773197f782c19ad86c5438a2cc199203774 + React-RCTAnimation: ad9dd2c6c3b4d07e583c2b79354858c4f34481a0 + React-RCTAppDelegate: 70398a06e10ada27cdf77dc2b43f883126a91ac0 + React-RCTBlob: f3d86b491b8f28c36ced0cb750878b62f72e1380 + React-RCTFabric: 3767f97183c40ba3dadf007b17a01be2cd4e632a + React-RCTFBReactNativeSpec: d7ad5d9edc1865f38b9aac5b7091c3abb6978eed + React-RCTImage: 46ad408f777dce991d4095d7e73a568212be6baa + React-RCTLinking: 547427cc885bfa74b3cbba405971c5270defde7a + React-RCTNetwork: 52c00c0fe07327df9b9fe9881b4f5550dc5ced37 + React-RCTRuntime: 081fd457d305c3aee76c335c568e693ed107f48e + React-RCTSettings: 9cd0b2be41404574ec280b6b8e73c2208c842050 + React-RCTText: 5a6d38456eabc0a1a7c0d47d592390d35c6de57c + React-RCTVibration: c1815b4f471462954a4b7d8835155e053cec5412 React-rendererconsistency: b7996da82c8d3f4a7928b39be3e437b72ad92012 - React-renderercss: 3b11f40c0c21140902dee115e8fefcf59f75c703 - React-rendererdebug: 331a5c2ebf9294b82eb3531e0e1efbaa0537a0bb - React-resizeobservernativemodule: 24a21a6d00e9dd360f4ef8bf4065040a8b5bc985 - React-RuntimeApple: 0aaf9964151b80c9efc8fd08a80e96ec9c7d60dd - React-RuntimeCore: df973653596b10d77a497c2c34a9f8325c307249 - React-runtimeexecutor: 5c613fede1667a12a38cfc566ff3026bfde3b5f7 - React-RuntimeHermes: d7bcefa9b395d1646c906c4112a1f8de7212e90b - React-runtimescheduler: 431db4de0f22bb2b3315cb728ac8983a566c955a - React-timing: 1d927443f5c37bb25dee28478ef1f20f05996626 - React-utils: d50a630c236f386a9ac019f360faf661e5c4717e - React-viewtransitionnativemodule: 8b0ce65faa32cdfc14aaa89680711cca3321c180 - React-webperformancenativemodule: 087b85db47f4e83dd719a03822986b6c2f073335 - ReactAppDependencyProvider: 1666a962dbb4b36824b6297f5fc83049dd7c3717 - ReactCodegen: 5b3cdb1f612a81f3b543a94f425ecd8518c32f2c - ReactCommon: c6895b36d81986f89a7e40a00b4b72ca70e82710 + React-renderercss: 4c256900eba87661178771766da0171493f88848 + React-rendererdebug: 4d9df8cf2cac6eee7002a4d14358c79fdf6ad8c5 + React-resizeobservernativemodule: 750d334554e7c44bacf14568a8a0d0048cc4c278 + React-RuntimeApple: 2045a6206895ad5ce90d141d1bd384888fd06c42 + React-RuntimeCore: b051facffbc7ca038097278cabf810d6d86dd328 + React-runtimeexecutor: b06ec9bb745a97cbd3ce25e3e02be7b8058fb374 + React-RuntimeHermes: fcfa8baca49a6d37d331147568d51d5b8b0a175d + React-runtimescheduler: c2afe74d1db006bafd9270186101f5378b1bef81 + React-timing: 6a1a8cfb0caae8de243aba16fa92fa81de23efaf + React-utils: 2384e5db98378df8c0bf2c0d5489ec1b8e80b398 + React-viewtransitionnativemodule: 8505b253586f792c6c722869a664889797ecae3e + React-webperformancenativemodule: 67f32fde92ed7e8470ee1c669bdb7c2fcb760141 + ReactAppDependencyProvider: 782ee9546c9cd3b53b73f1e9e3dd728540085fc7 + ReactCodegen: 7b71f4464442e9b6eae41094d11076d56c51c0e3 + ReactCommon: 145a14b942b19fc2fe38927f261955ada56978aa ReactNativeDependencies: d3b7423ba1e52525e42085c8470109abde583d2e - ReactNativeEnrichedHtml: 1c9c0a82045119189130ba3be08eb0d40c25d992 - SocketRocket: d57b1af80c029e12a75cd9b218287c67381e4593 - Yoga: 58b502c52b14ad3c4468805d461fc37d275c2a42 + ReactNativeEnrichedHtml: 60c1875f2b13a40159671643a30f488ca1c49220 + SocketRocket: 37aec555668fb852ec12e3c0de59a86ca58f0871 + Yoga: d1c536142c5ff8ec8cd856ab2a7c227a1d875c8e PODFILE CHECKSUM: 17de42bc1248ff5392a5a74f9edf4660b05a1695 -COCOAPODS: 1.15.2 +COCOAPODS: 1.17.0 diff --git a/apps/example/src/screens/DevScreen.tsx b/apps/example/src/screens/DevScreen.tsx index d5b4ba3f1..4d3853aac 100644 --- a/apps/example/src/screens/DevScreen.tsx +++ b/apps/example/src/screens/DevScreen.tsx @@ -62,6 +62,7 @@ export function DevScreen({ onSwitch }: DevScreenProps) { onEndMention={editor.handleEndMention} onFocus={editor.handleFocusEvent} onBlur={editor.handleBlurEvent} + onScroll={(e) => console.log(e)} onChangeSelection={(e) => editor.handleSelectionChangeEvent(e.nativeEvent) } diff --git a/apps/example/src/screens/TestScreen.tsx b/apps/example/src/screens/TestScreen.tsx index 160fda327..841a458e2 100644 --- a/apps/example/src/screens/TestScreen.tsx +++ b/apps/example/src/screens/TestScreen.tsx @@ -85,6 +85,9 @@ export function TestScreen({ onEndMention={editor.handleEndMention} onFocus={editor.handleFocusEvent} onBlur={editor.handleBlurEvent} + onScroll={(e) => + console.log([e.nativeEvent.contentOffset, e.timeStamp]) + } onChangeSelection={(e) => editor.handleSelectionChangeEvent(e.nativeEvent) } diff --git a/ios/EnrichedTextInputView.mm b/ios/EnrichedTextInputView.mm index c44d4d9dd..b5b35932e 100644 --- a/ios/EnrichedTextInputView.mm +++ b/ios/EnrichedTextInputView.mm @@ -62,6 +62,8 @@ @implementation EnrichedTextInputView { NSString *_submitBehavior; NSDictionary *_capturedAttributesBeforeChange; NSString *_recentlyEmittedAlignment; + CFTimeInterval _scrollLastTick; + int _scrollEventThrottle; } @synthesize blockEmitting = blockEmitting; @@ -599,6 +601,10 @@ - (void)updateProps:(Props::Shared const &)props [textView setScrollEnabled:newViewProps.scrollEnabled]; } + if (newViewProps.scrollEventThrottle != oldViewProps.scrollEventThrottle) { + _scrollEventThrottle = newViewProps.scrollEventThrottle; + } + if (newViewProps.allowFontScaling != oldViewProps.allowFontScaling) { [newConfig setAllowFontScaling:newViewProps.allowFontScaling]; stylePropChanged = YES; @@ -1501,6 +1507,29 @@ - (void)emitOnKeyPressEvent:(NSString *)key { emitter->onInputKeyPress({.key = [key toCppString]}); } } +- (void)scrollViewDidScroll:(UIScrollView *)scrollView { + NSLog(@"[Enriched] y=%.0f contentH=%.0f boundsH=%.0f", + scrollView.contentOffset.y, scrollView.contentSize.height, + scrollView.bounds.size.height); + + auto now = CACurrentMediaTime(); + // now is in seconds _scrollEventThrottle is in miliseconds + if (now - _scrollLastTick < _scrollEventThrottle / 1000.0) { + return; + } + _scrollLastTick = now; + [self emitOnScroll:scrollView]; +} + +- (void)emitOnScroll:(UIScrollView *)scrollView { + auto emitter = [self getEventEmitter]; + if (emitter != nullptr) { + emitter->onInputScroll({.contentOffset = { + .x = (int)scrollView.contentOffset.x, + .y = (int)scrollView.contentOffset.y, + }}); + } +} // MARK: - Styles manipulation diff --git a/src/native/EnrichedTextInput.tsx b/src/native/EnrichedTextInput.tsx index cfe12104c..c50475063 100644 --- a/src/native/EnrichedTextInput.tsx +++ b/src/native/EnrichedTextInput.tsx @@ -75,6 +75,7 @@ export const EnrichedTextInput = ({ onChangeSelection, onKeyPress, onSubmitEditing, + onScroll, returnKeyType, returnKeyLabel, submitBehavior, @@ -83,6 +84,7 @@ export const EnrichedTextInput = ({ androidExperimentalSynchronousEvents = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.androidExperimentalSynchronousEvents, useHtmlNormalizer = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.useHtmlNormalizer, scrollEnabled = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.scrollEnabled, + scrollEventThrottle = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.scrollEventThrottle, allowFontScaling = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.allowFontScaling, ...rest }: EnrichedTextInputProps) => { @@ -350,6 +352,7 @@ export const EnrichedTextInput = ({ onInputBlur={onBlur} onChangeText={onChangeText} onChangeHtml={onChangeHtml} + onInputScroll={onScroll} isOnChangeHtmlSet={onChangeHtml !== undefined} isOnChangeTextSet={onChangeText !== undefined} onChangeState={onChangeState} @@ -371,6 +374,7 @@ export const EnrichedTextInput = ({ } useHtmlNormalizer={useHtmlNormalizer} scrollEnabled={scrollEnabled} + scrollEventThrottle={scrollEventThrottle} allowFontScaling={allowFontScaling} {...rest} /> diff --git a/src/spec/EnrichedTextInputNativeComponent.ts b/src/spec/EnrichedTextInputNativeComponent.ts index c5d2e61e3..8c49da5ca 100644 --- a/src/spec/EnrichedTextInputNativeComponent.ts +++ b/src/spec/EnrichedTextInputNativeComponent.ts @@ -306,6 +306,13 @@ type Heading = { bold?: boolean; }; +export interface OnScrollEvent { + contentOffset: { + x: CodegenTypes.Int32; + y: CodegenTypes.Int32; + }; +} + export interface HtmlStyleInternal { h1?: Heading; h2?: Heading; @@ -370,6 +377,7 @@ export interface NativeProps extends ViewProps { spellCheck?: boolean; htmlStyle?: HtmlStyleInternal; scrollEnabled?: boolean; + scrollEventThrottle?: CodegenTypes.Int32; linkRegex?: LinkNativeRegex; contextMenuItems?: ReadonlyArray>; textShortcuts: ReadonlyArray>; @@ -390,6 +398,7 @@ export interface NativeProps extends ViewProps { onChangeSelection?: CodegenTypes.DirectEventHandler; onRequestHtmlResult?: CodegenTypes.DirectEventHandler; onInputKeyPress?: CodegenTypes.DirectEventHandler; + onInputScroll?: CodegenTypes.DirectEventHandler; onPasteImages?: CodegenTypes.DirectEventHandler; onContextMenuItemPress?: CodegenTypes.DirectEventHandler; onSubmitEditing?: CodegenTypes.BubblingEventHandler; diff --git a/src/types.ts b/src/types.ts index 570cf0b1a..c0dacefb9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -698,6 +698,12 @@ export interface EnrichedTextInputProps extends Omit { */ scrollEnabled?: boolean; + /** + * The number of milliseconds to throttle scroll events. + * Defaults to `16`. + */ + scrollEventThrottle?: number; + /** * Regular expression used to auto-detect links as the user types. Set to * `null` to disable automatic link detection. Defaults to a built-in URL diff --git a/src/web/EnrichedTextInput.tsx b/src/web/EnrichedTextInput.tsx index cb01018a7..500e97633 100644 --- a/src/web/EnrichedTextInput.tsx +++ b/src/web/EnrichedTextInput.tsx @@ -110,6 +110,7 @@ export const EnrichedTextInput = ({ autoCapitalize = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.autoCapitalize, scrollEnabled = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.scrollEnabled, mentionIndicators = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.mentionIndicators.slice(), + scrollEventThrottle = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.scrollEventThrottle, onFocus, style, onBlur, @@ -197,10 +198,7 @@ export const EnrichedTextInput = ({ const handleScroll = (event: React.UIEvent) => { if ( - !shouldEmitScrollEvent( - scrollLastTickRef.current, - ENRICHED_TEXT_INPUT_DEFAULT_PROPS.scrollEventThrottle - ) + !shouldEmitScrollEvent(scrollLastTickRef.current, scrollEventThrottle) ) { return; } From 4aa81bfeb15518f46f59aeb8de1e67a1275eeadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Tue, 27 Oct 2026 15:30:34 +0100 Subject: [PATCH 05/28] fix: fix the layout scroll loop --- ios/enrichedInputTextView/EnrichedInputTextView.mm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ios/enrichedInputTextView/EnrichedInputTextView.mm b/ios/enrichedInputTextView/EnrichedInputTextView.mm index 4dcba8bc4..c363608f9 100644 --- a/ios/enrichedInputTextView/EnrichedInputTextView.mm +++ b/ios/enrichedInputTextView/EnrichedInputTextView.mm @@ -7,13 +7,22 @@ #import "utils/TextListsUtils.h" #import -@implementation EnrichedInputTextView +@implementation EnrichedInputTextView { + CGSize _lastLayoutSize; +} - (void)layoutSubviews { [super layoutSubviews]; // UITextView resets contentSize during its own layout pass (triggered when // the frame is set on first mount). Re-schedule a relayout so our explicit // contentSize is applied after UITextView finishes its internal layout. + // layoutSubviews also runs on every scroll (only bounds.origin changes), so + // relayout only when the size changed to avoid a relayout <-> scroll loop. + if (CGSizeEqualToSize(self.bounds.size, _lastLayoutSize)) { + return; + } + _lastLayoutSize = self.bounds.size; + EnrichedTextInputView *input = (EnrichedTextInputView *)_input; if (input != nil) { [input scheduleRelayoutIfNeeded]; From 746be5be65f07dc46764c08c988d4127ede9c401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Tue, 27 Oct 2026 15:43:31 +0100 Subject: [PATCH 06/28] refactor: add handler for debuging scrollEvent in example app --- apps/example/src/hooks/useEditorState.ts | 6 ++++++ apps/example/src/screens/DevScreen.tsx | 2 +- apps/example/src/screens/TestScreen.tsx | 4 +--- ios/EnrichedTextInputView.mm | 4 ---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/example/src/hooks/useEditorState.ts b/apps/example/src/hooks/useEditorState.ts index 69dcc3048..0b9e588c5 100644 --- a/apps/example/src/hooks/useEditorState.ts +++ b/apps/example/src/hooks/useEditorState.ts @@ -26,6 +26,7 @@ import { prepareImageDimensions, } from '../utils/prepareImageDimensions'; import { launchImageLibrary } from 'react-native-image-picker'; +import type { OnScrollEvent } from '../../../../src/types'; type CurrentLinkState = OnLinkDetected; @@ -159,6 +160,10 @@ export function useEditorState() { console.log('Key pressed:', e.key); }; + const handleScroll = (e: OnScrollEvent) => { + console.log('Scroll event:', e.contentOffset); + }; + const handleLinkDetected = (state: CurrentLinkState) => { console.log(state); setCurrentLink(state); @@ -267,6 +272,7 @@ export function useEditorState() { handleSelectionChangeEvent, handleKeyPress, handleFocusEvent, + handleScroll, handleBlurEvent, handlePasteImagesEvent, handleStartMention, diff --git a/apps/example/src/screens/DevScreen.tsx b/apps/example/src/screens/DevScreen.tsx index 4d3853aac..0b50b274c 100644 --- a/apps/example/src/screens/DevScreen.tsx +++ b/apps/example/src/screens/DevScreen.tsx @@ -62,7 +62,7 @@ export function DevScreen({ onSwitch }: DevScreenProps) { onEndMention={editor.handleEndMention} onFocus={editor.handleFocusEvent} onBlur={editor.handleBlurEvent} - onScroll={(e) => console.log(e)} + onScroll={(e) => editor.handleScroll(e.nativeEvent)} onChangeSelection={(e) => editor.handleSelectionChangeEvent(e.nativeEvent) } diff --git a/apps/example/src/screens/TestScreen.tsx b/apps/example/src/screens/TestScreen.tsx index 841a458e2..d52b2e31e 100644 --- a/apps/example/src/screens/TestScreen.tsx +++ b/apps/example/src/screens/TestScreen.tsx @@ -85,9 +85,7 @@ export function TestScreen({ onEndMention={editor.handleEndMention} onFocus={editor.handleFocusEvent} onBlur={editor.handleBlurEvent} - onScroll={(e) => - console.log([e.nativeEvent.contentOffset, e.timeStamp]) - } + onScroll={(e) => editor.handleScroll(e.nativeEvent)} onChangeSelection={(e) => editor.handleSelectionChangeEvent(e.nativeEvent) } diff --git a/ios/EnrichedTextInputView.mm b/ios/EnrichedTextInputView.mm index b5b35932e..97a05510a 100644 --- a/ios/EnrichedTextInputView.mm +++ b/ios/EnrichedTextInputView.mm @@ -1508,10 +1508,6 @@ - (void)emitOnKeyPressEvent:(NSString *)key { } } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { - NSLog(@"[Enriched] y=%.0f contentH=%.0f boundsH=%.0f", - scrollView.contentOffset.y, scrollView.contentSize.height, - scrollView.bounds.size.height); - auto now = CACurrentMediaTime(); // now is in seconds _scrollEventThrottle is in miliseconds if (now - _scrollLastTick < _scrollEventThrottle / 1000.0) { From 8c54bbcb5844a74ff8fe1655c67897dfcf6af74a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Tue, 27 Oct 2026 15:45:48 +0100 Subject: [PATCH 07/28] refactor: change the import path for onScrollEvent --- apps/example/src/hooks/useEditorState.ts | 2 +- src/index.native.tsx | 1 + src/index.tsx | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/example/src/hooks/useEditorState.ts b/apps/example/src/hooks/useEditorState.ts index 0b9e588c5..8b24c7ccc 100644 --- a/apps/example/src/hooks/useEditorState.ts +++ b/apps/example/src/hooks/useEditorState.ts @@ -10,6 +10,7 @@ import { type OnKeyPressEvent, type OnPasteImagesEvent, type OnSubmitEditing, + type OnScrollEvent, } from 'react-native-enriched-html'; import { useRef, useState } from 'react'; import { type MentionItem } from '../components/MentionPopup'; @@ -26,7 +27,6 @@ import { prepareImageDimensions, } from '../utils/prepareImageDimensions'; import { launchImageLibrary } from 'react-native-image-picker'; -import type { OnScrollEvent } from '../../../../src/types'; type CurrentLinkState = OnLinkDetected; diff --git a/src/index.native.tsx b/src/index.native.tsx index 8f7473c7a..23a2a073e 100644 --- a/src/index.native.tsx +++ b/src/index.native.tsx @@ -10,6 +10,7 @@ export type { OnMentionDetected, OnChangeSelectionEvent, OnKeyPressEvent, + OnScrollEvent, OnPasteImagesEvent, OnSubmitEditing, HtmlStyle, diff --git a/src/index.tsx b/src/index.tsx index e6b4e654a..2203afb39 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -11,6 +11,7 @@ export type { OnMentionDetected, OnChangeSelectionEvent, OnKeyPressEvent, + OnScrollEvent, OnPasteImagesEvent, OnSubmitEditing, HtmlStyle, From fe40d4cf37fdb118dd679a74e199290a176e1658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Wed, 28 Oct 2026 11:46:06 +0100 Subject: [PATCH 08/28] feat: added onScroll on android --- .../textinput/EnrichedTextInputView.kt | 26 +++++++++++++++++ .../textinput/EnrichedTextInputViewManager.kt | 11 ++++++- .../textinput/events/OnInputScrollEvent.kt | 29 +++++++++++++++++++ apps/example-web/src/App.tsx | 6 ++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 android/src/main/java/com/swmansion/enriched/textinput/events/OnInputScrollEvent.kt diff --git a/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt b/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt index e61435f35..a91877d1a 100644 --- a/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt +++ b/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt @@ -9,6 +9,7 @@ import android.graphics.Color import android.graphics.Rect import android.graphics.text.LineBreaker import android.os.Build +import android.os.SystemClock import android.text.Editable import android.text.InputType import android.text.Spannable @@ -47,6 +48,7 @@ import com.swmansion.enriched.textinput.events.MentionHandler import com.swmansion.enriched.textinput.events.OnContextMenuItemPressEvent import com.swmansion.enriched.textinput.events.OnInputBlurEvent import com.swmansion.enriched.textinput.events.OnInputFocusEvent +import com.swmansion.enriched.textinput.events.OnInputScrollEvent import com.swmansion.enriched.textinput.events.OnRequestHtmlResultEvent import com.swmansion.enriched.textinput.events.OnSubmitEditingEvent import com.swmansion.enriched.textinput.spans.EnrichedInputH1Span @@ -94,6 +96,8 @@ class EnrichedTextInputView : var isDuringTransaction: Boolean = false var isRemovingMany: Boolean = false var scrollEnabled: Boolean = true + var scrollEventThrottle: Int = 0 + private var scrollLastTick:Long = 0 var allowFontScaling: Boolean = EnrichedConstants.ALLOW_FONT_SCALING_DEFAULT set(value) { if (field != value) { @@ -315,6 +319,28 @@ class EnrichedTextInputView : override fun canScrollHorizontally(direction: Int): Boolean = scrollEnabled + override fun onScrollChanged(horiz: Int, vert: Int, oldHoriz: Int, oldVert: Int) { + super.onScrollChanged(horiz, vert, oldHoriz, oldVert) + + val now = SystemClock.uptimeMillis() + if (now - scrollLastTick > scrollEventThrottle) { + scrollLastTick = now + val reactContext = context as? ReactContext ?: return + val surfaceId = UIManagerHelper.getSurfaceId(reactContext) + val dispatcher = UIManagerHelper.getEventDispatcher(reactContext) + + dispatcher?.dispatchEvent( + OnInputScrollEvent( + surfaceId, + id, + horiz, + vert, + experimentalSynchronousEvents, + ), + ) + } + } + override fun onSelectionChanged( selStart: Int, selEnd: Int, diff --git a/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputViewManager.kt b/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputViewManager.kt index 8b43f3280..5d01d0d58 100644 --- a/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputViewManager.kt +++ b/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputViewManager.kt @@ -23,6 +23,7 @@ import com.swmansion.enriched.textinput.events.OnContextMenuItemPressEvent import com.swmansion.enriched.textinput.events.OnInputBlurEvent import com.swmansion.enriched.textinput.events.OnInputFocusEvent import com.swmansion.enriched.textinput.events.OnInputKeyPressEvent +import com.swmansion.enriched.textinput.events.OnInputScrollEvent import com.swmansion.enriched.textinput.events.OnLinkDetectedEvent import com.swmansion.enriched.textinput.events.OnMentionDetectedEvent import com.swmansion.enriched.textinput.events.OnMentionEvent @@ -76,7 +77,7 @@ class EnrichedTextInputViewManager : map.put(OnPasteImagesEvent.EVENT_NAME, mapOf("registrationName" to OnPasteImagesEvent.EVENT_NAME)) map.put(OnContextMenuItemPressEvent.EVENT_NAME, mapOf("registrationName" to OnContextMenuItemPressEvent.EVENT_NAME)) map.put(OnSubmitEditingEvent.EVENT_NAME, mapOf("registrationName" to OnSubmitEditingEvent.EVENT_NAME)) - + map.put(OnInputScrollEvent.EVENT_NAME, mapOf("registrationName" to OnInputScrollEvent.EVENT_NAME)) return map } @@ -241,6 +242,14 @@ class EnrichedTextInputViewManager : view.scrollEnabled = scrollEnabled } + @ReactProp(name = "scrollEventThrottle") + override fun setScrollEventThrottle( + view: EnrichedTextInputView, + value: Int, + ) { + view.scrollEventThrottle = value + } + @ReactProp(name = "allowFontScaling") override fun setAllowFontScaling( view: EnrichedTextInputView, diff --git a/android/src/main/java/com/swmansion/enriched/textinput/events/OnInputScrollEvent.kt b/android/src/main/java/com/swmansion/enriched/textinput/events/OnInputScrollEvent.kt new file mode 100644 index 000000000..cf9e499e1 --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/textinput/events/OnInputScrollEvent.kt @@ -0,0 +1,29 @@ +package com.swmansion.enriched.textinput.events + +import com.facebook.react.bridge.Arguments +import com.facebook.react.bridge.WritableMap +import com.facebook.react.uimanager.events.Event + +class OnInputScrollEvent( + surfaceId: Int, + viewId: Int, + private val contentOffsetX: Int, + private val contentOffsetY: Int, + private val experimentalSynchronousEvents: Boolean, +): Event(surfaceId, viewId) { + override fun getEventName(): String = EVENT_NAME + override fun getEventData(): WritableMap { + val eventData = Arguments.createMap() + val contentOffset = Arguments.createMap() + contentOffset.putInt("x", contentOffsetX) + contentOffset.putInt("y", contentOffsetY) + eventData.putMap("contentOffset", contentOffset) + return eventData + } + + override fun experimental_isSynchronous(): Boolean = experimentalSynchronousEvents + + companion object { + const val EVENT_NAME: String = "onInputScroll" + } +} diff --git a/apps/example-web/src/App.tsx b/apps/example-web/src/App.tsx index 5718b75de..e9e15174a 100644 --- a/apps/example-web/src/App.tsx +++ b/apps/example-web/src/App.tsx @@ -15,6 +15,7 @@ import { type OnChangeMentionEvent, type OnMentionDetected, type OnLinkPressEvent, + type OnScrollEvent, } from 'react-native-enriched-html'; import { WEB_DEFAULT_HTML_STYLE } from './defaultHtmlStyle'; import type { NativeSyntheticEvent } from 'react-native'; @@ -252,6 +253,10 @@ function App() { }); }; + const handleScroll = (e: NativeSyntheticEvent) => { + console.log('[EnrichedTextInput] onScroll event', e.nativeEvent); + }; + return (

Enriched Text Input

@@ -271,6 +276,7 @@ function App() { scrollEnabled autoCapitalize="sentences" style={enrichedInputStyle} + onScroll={handleScroll} onFocus={handleFocus} onBlur={handleBlur} onKeyPress={handleKeyPress} From b953d354b962e687df3eec9e4f9c845c397c2cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Wed, 28 Oct 2026 12:51:53 +0100 Subject: [PATCH 09/28] feat(web): add e2e tests --- .playwright/tests/scroll.spec.ts | 35 ++++++++++++++++++++++++++ apps/example-web/src/RouteSelector.tsx | 5 ++++ 2 files changed, 40 insertions(+) create mode 100644 .playwright/tests/scroll.spec.ts diff --git a/.playwright/tests/scroll.spec.ts b/.playwright/tests/scroll.spec.ts new file mode 100644 index 000000000..3df5d9146 --- /dev/null +++ b/.playwright/tests/scroll.spec.ts @@ -0,0 +1,35 @@ +import { test, expect, type Page } from '@playwright/test'; + +const sel = { + editor: '[data-testid="scroll-editor"]', + offsetOutput: '[data-testid="scroll-offset-output"]', +} as const; + +async function readOffset(page: Page): Promise { + return Number(await page.locator(sel.offsetOutput).textContent()); +} + +test.beforeEach(async ({ page }) => { + await page.goto('/test-scroll'); + await page.locator(sel.editor).hover(); +}); + +test('onScroll reports content offset', async ({ page }) => { + await page.mouse.wheel(0, 300); + await expect(page.locator(sel.offsetOutput)).not.toHaveText('0'); +}); + +test('scrolling down increases and scrolling up decreases the offset', async ({ + page, +}) => { + await page.mouse.wheel(0, 200); + await expect.poll(() => readOffset(page)).toBeGreaterThan(0); + const afterFirstScroll = await readOffset(page); + + await page.mouse.wheel(0, 200); + await expect.poll(() => readOffset(page)).toBeGreaterThan(afterFirstScroll); + const afterSecondScroll = await readOffset(page); + + await page.mouse.wheel(0, -200); + await expect.poll(() => readOffset(page)).toBeLessThan(afterSecondScroll); +}); diff --git a/apps/example-web/src/RouteSelector.tsx b/apps/example-web/src/RouteSelector.tsx index d280fb214..cfa78f6dd 100644 --- a/apps/example-web/src/RouteSelector.tsx +++ b/apps/example-web/src/RouteSelector.tsx @@ -8,6 +8,7 @@ import { TestEnrichedText } from './testScreens/TestEnrichedText'; import { TestEllipsize } from './testScreens/TestEllipsize'; import { TestRenderCycle } from './testScreens/TestRenderCycle'; import { useEffect, useState } from 'react'; +import { TestScroll } from './testScreens/TestScroll'; export default function RouteSelector() { const [path, setPath] = useState(window.location.pathname); @@ -55,5 +56,9 @@ export default function RouteSelector() { return ; } + if (path === '/test-scroll') { + return ; + } + return ; } From 73ce67a003d9028c329302ceea41274c07d97099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Wed, 28 Oct 2026 13:50:38 +0100 Subject: [PATCH 10/28] feat: more towards e2e test --- .maestro/enrichedInput/flows/scroll.yaml | 26 +++++++++++++++++++ .maestro/scripts/setup-ios-simulator.sh | 4 ++- .../src/testScreens/TestScroll.tsx | 22 ++++++++++++++++ apps/example/src/screens/TestScreen.tsx | 20 ++++++++++++-- 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 .maestro/enrichedInput/flows/scroll.yaml create mode 100644 apps/example-web/src/testScreens/TestScroll.tsx diff --git a/.maestro/enrichedInput/flows/scroll.yaml b/.maestro/enrichedInput/flows/scroll.yaml new file mode 100644 index 000000000..f7f205aa7 --- /dev/null +++ b/.maestro/enrichedInput/flows/scroll.yaml @@ -0,0 +1,26 @@ +appId: swmansion.enriched.example +--- +- launchApp + +- tapOn: + id: "toggle-screen-button" + +- runFlow: + file: "../subflows/set_editor_value.yaml" + env: + VALUE: "

Line 1

Line 2

Line 3

Line 4

Line 5

Line 6

Line 7

Line 8

Line 9

Line 10

Line 11

Line 12

Line 13

Line 14

Line 15

" + +- assertVisible: + id: "scroll-offset-output" + text: "Scroll offset: 0.00" + +- swipe: + from: + id: "editor-input" + direction: UP + +- waitForAnimationToEnd + +- assertNotVisible: + id: "scroll-offset-output" + text: "Scroll offset: 0.00" diff --git a/.maestro/scripts/setup-ios-simulator.sh b/.maestro/scripts/setup-ios-simulator.sh index 5f9d8ea23..0de6c3509 100755 --- a/.maestro/scripts/setup-ios-simulator.sh +++ b/.maestro/scripts/setup-ios-simulator.sh @@ -46,7 +46,9 @@ if [ "$STATE" != "(Booted)" ]; then xcrun simctl boot "$UDID" fi -open -a Simulator +# Newer Xcode versions replace Simulator.app with DeviceHub.app. Showing the +# window is optional, the device is already booted. +open -a Simulator 2>/dev/null || open -b com.apple.dt.Devices 2>/dev/null || true echo "Simulator ready: $DEVICE_NAME ($UDID)" echo "DEVICE_ID=$UDID" diff --git a/apps/example-web/src/testScreens/TestScroll.tsx b/apps/example-web/src/testScreens/TestScroll.tsx new file mode 100644 index 000000000..ca3d3a8a3 --- /dev/null +++ b/apps/example-web/src/testScreens/TestScroll.tsx @@ -0,0 +1,22 @@ +import { EnrichedTextInput } from 'react-native-enriched-html'; +import { useState } from 'react'; + +const LONG_HTML = '

Test


'.repeat(150); + +export function TestScroll() { + const [offset, setOffset] = useState(0); + return ( +
+
+ { + setOffset(e.nativeEvent.contentOffset.y); + }} + /> +
+
{offset}
+
+ ); +} diff --git a/apps/example/src/screens/TestScreen.tsx b/apps/example/src/screens/TestScreen.tsx index d52b2e31e..6f48bf2cc 100644 --- a/apps/example/src/screens/TestScreen.tsx +++ b/apps/example/src/screens/TestScreen.tsx @@ -1,5 +1,5 @@ import { useState } from 'react'; -import { View, StyleSheet, ScrollView } from 'react-native'; +import { View, StyleSheet, ScrollView, Text } from 'react-native'; import { EnrichedTextInput } from 'react-native-enriched-html'; import { Button } from '../components/Button'; import { Toolbar } from '../components/Toolbar'; @@ -25,6 +25,7 @@ export function TestScreen({ }: TestScreenProps) { const editor = useEditorState(); const [sizeMode, setSizeMode] = useState<'base' | 'max'>('base'); + const [scrollOffset, setScrollOffset] = useState(0); return ( @@ -85,7 +86,10 @@ export function TestScreen({ onEndMention={editor.handleEndMention} onFocus={editor.handleFocusEvent} onBlur={editor.handleBlurEvent} - onScroll={(e) => editor.handleScroll(e.nativeEvent)} + onScroll={(e) => { + editor.handleScroll(e.nativeEvent); + setScrollOffset(e.nativeEvent.contentOffset.y); + }} onChangeSelection={(e) => editor.handleSelectionChangeEvent(e.nativeEvent) } @@ -106,6 +110,9 @@ export function TestScreen({ onSelectImage={editor.openImageModal} layout="grid" /> + + Scroll offset: {scrollOffset.toFixed(2)} +