Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
34b2290
feat: add onScroll event to web
Oct 26, 2026
beb0696
feat: add scroll event throtling on web
Oct 26, 2026
da69d5f
refactor: changed the throttle ref to a number not an object
Oct 26, 2026
cff0e77
Merge branch 'main' of https://github.com/software-mansion/react-nati…
Oct 26, 2026
a29b77f
feat: add onScroll on ios
Oct 27, 2026
4aa81bf
fix: fix the layout scroll loop
Oct 27, 2026
746be5b
refactor: add handler for debuging scrollEvent in example app
Oct 27, 2026
8c54bbc
refactor: change the import path for onScrollEvent
Oct 27, 2026
fe40d4c
feat: added onScroll on android
Oct 28, 2026
b953d35
feat(web): add e2e tests
Oct 28, 2026
73ce67a
feat: more towards e2e test
Oct 28, 2026
ad95c50
feat(mobile): add more cases to tests
Oct 28, 2026
0a2ba65
fix(android): set input min height to avoid an unwanted scroll
Oct 29, 2026
0f1bcd0
fix: fix the tests on android
Oct 29, 2026
31b11c5
merge main
Oct 29, 2026
cbb9979
refactor: restore podfile.lock
Oct 29, 2026
5af689d
fix: restore podfile.lock again
Oct 29, 2026
e1d8f23
fix: fix the lint issues
Oct 29, 2026
2e5d181
refactor: remove throtling to behave more like react native
Oct 30, 2026
b494dcd
refactor: removed the helper on android to match the code on other pl…
Oct 30, 2026
137db01
Merge branch 'main' of https://github.com/software-mansion/react-nati…
Nov 3, 2026
bdd7812
feat: change mobile scroll tests
relextm19 Nov 4, 2026
4007cb3
fix(android): fix bug in android scroll event emission
relextm19 Nov 4, 2026
a9ef2bc
refactor: more suiting comment
relextm19 Nov 4, 2026
ce0bc6f
fix(web): stop react from useless rerendering
relextm19 Nov 4, 2026
367e352
feat: add docs for onScroll
relextm19 Nov 4, 2026
60c7091
feat(ios): only emmit scrollEvent when contentOffset changes
relextm19 Nov 4, 2026
8561157
Merge branch 'main' of https://github.com/software-mansion/react-nati…
relextm19 Nov 4, 2026
91cca3a
fix(ios): lint fix
relextm19 Nov 4, 2026
4a30f60
feat: only calculate scroll offset if we have a handler
relextm19 Nov 11, 2026
17fe873
fix: fix lint warning
relextm19 Nov 11, 2026
2cdeddd
feat: add update delay in scroll tests
relextm19 Nov 11, 2026
3d0ce66
Merge branch 'main' into @relextm19/scroll-position
szydlovsky Nov 12, 2026
2ff17fd
Merge branch 'main' into @relextm19/scroll-position
szydlovsky Nov 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .maestro/enrichedInput/flows/on_scroll_event.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
appId: swmansion.enriched.example
---
- launchApp:
arguments:
showScrollOffset: true

- tapOn:
id: "toggle-screen-button"

- runFlow:
file: "../subflows/set_editor_value.yaml"
env:
VALUE: "1<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>2"

# Setting the value scrolls the input to the bottom on Android, so scroll back to the top
- runFlow:
when:
platform: Android
commands:
- repeat:
times: 10
while:
notVisible:
id: "scroll-offset-output"
text: "Scroll offset: 0.00"
commands:
- swipe:
from:
id: "editor-input"
direction: DOWN
duration: 300
- waitForAnimationToEnd

- swipe:
from:
id: "editor-input"
direction: UP
duration: 1000
- waitForAnimationToEnd
- copyTextFrom:
id: "scroll-offset-output"
- evalScript: "${output.afterFirstScroll = parseFloat(maestro.copiedText.match(/[0-9.]+/)[0])}"
- assertTrue: "${output.afterFirstScroll > 0}"

- swipe:
from:
id: "editor-input"
direction: UP
duration: 1000
- waitForAnimationToEnd
- copyTextFrom:
id: "scroll-offset-output"
- evalScript: "${output.afterSecondScroll = parseFloat(maestro.copiedText.match(/[0-9.]+/)[0])}"
- assertTrue: "${output.afterSecondScroll > output.afterFirstScroll}"

- swipe:
from:
id: "editor-input"
direction: DOWN
duration: 1000
- waitForAnimationToEnd
- copyTextFrom:
id: "scroll-offset-output"
- evalScript: "${output.afterScrollUp = parseFloat(maestro.copiedText.match(/[0-9.]+/)[0])}"
- assertTrue: "${output.afterScrollUp < output.afterSecondScroll}"
35 changes: 35 additions & 0 deletions .playwright/tests/scroll.spec.ts
Original file line number Diff line number Diff line change
@@ -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<number> {
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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.ReactConstants
import com.facebook.react.uimanager.PixelUtil
import com.facebook.react.uimanager.StateWrapper
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.views.text.ReactTypefaceUtils.applyStyles
Expand All @@ -49,6 +50,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
Expand Down Expand Up @@ -131,6 +133,7 @@ class EnrichedTextInputView :

var shouldEmitHtml: Boolean = false
var shouldEmitOnChangeText: Boolean = false
var shouldEmitOnScroll: Boolean = false
var experimentalSynchronousEvents: Boolean = false
var useHtmlNormalizer: Boolean = false

Expand Down Expand Up @@ -341,6 +344,34 @@ 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)
if (!shouldEmitOnScroll) return
if (horiz == oldHoriz && vert == oldVert) return

val reactContext = context as? ReactContext ?: return
val surfaceId = UIManagerHelper.getSurfaceId(reactContext)
val dispatcher = UIManagerHelper.getEventDispatcher(reactContext)

val dipHorizontal = PixelUtil.toDIPFromPixel(horiz.toFloat())
val dipVertical = PixelUtil.toDIPFromPixel(vert.toFloat())

dispatcher?.dispatchEvent(
OnInputScrollEvent(
surfaceId,
id,
dipHorizontal,
dipVertical,
experimentalSynchronousEvents,
),
)
}

override fun onSelectionChanged(
selStart: Int,
selEnd: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -296,6 +297,13 @@ class EnrichedTextInputViewManager :
view?.shouldEmitOnChangeText = value
}

override fun setIsOnScrollSet(
view: EnrichedTextInputView?,
value: Boolean,
) {
view?.shouldEmitOnScroll = value
}

override fun setAutoCapitalize(
view: EnrichedTextInputView?,
flag: String?,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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: Float,
private val contentOffsetY: Float,
private val experimentalSynchronousEvents: Boolean,
) : Event<OnInputScrollEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

override fun getEventData(): WritableMap {
val eventData = Arguments.createMap()
val contentOffset = Arguments.createMap()
contentOffset.putDouble("x", contentOffsetX.toDouble())
contentOffset.putDouble("y", contentOffsetY.toDouble())
eventData.putMap("contentOffset", contentOffset)
return eventData
}

override fun experimental_isSynchronous(): Boolean = experimentalSynchronousEvents

companion object {
const val EVENT_NAME: String = "onInputScroll"
}
}
6 changes: 6 additions & 0 deletions apps/example-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -252,6 +253,10 @@ function App() {
});
};

const handleScroll = (e: NativeSyntheticEvent<OnScrollEvent>) => {
console.log('[EnrichedTextInput] onScroll event', e.nativeEvent);
};

return (
<div className="container">
<h1 className="app-title">Enriched Text Input</h1>
Expand All @@ -271,6 +276,7 @@ function App() {
scrollEnabled
autoCapitalize="sentences"
style={enrichedInputStyle}
onScroll={handleScroll}
onFocus={handleFocus}
onBlur={handleBlur}
onKeyPress={handleKeyPress}
Expand Down
5 changes: 5 additions & 0 deletions apps/example-web/src/RouteSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -55,5 +56,9 @@ export default function RouteSelector() {
return <TestRenderCycle />;
}

if (path === '/test-scroll') {
return <TestScroll />;
}

return <App />;
}
28 changes: 28 additions & 0 deletions apps/example-web/src/testScreens/TestScroll.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { EnrichedTextInput } from 'react-native-enriched-html';
import { useState } from 'react';

const LONG_HTML = '<p>Test</p><br>'.repeat(150);

export function TestScroll() {
const [offset, setOffset] = useState(0);
return (
<div data-testid="test-scroll-root">
<div data-testid="scroll-editor">
<EnrichedTextInput
style={styles.editor}
defaultValue={LONG_HTML}
onScroll={(e) => {
setOffset(e.nativeEvent.contentOffset.y);
}}
/>
</div>
<div data-testid="scroll-offset-output">{offset}</div>
</div>
);
}

const styles = {
editor: {
height: 150,
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package swmansion.enriched.example

import android.os.Bundle
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
Expand All @@ -18,5 +19,14 @@ class MainActivity : ReactActivity() {
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
*/
override fun createReactActivityDelegate(): ReactActivityDelegate =
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
object : DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled) {
// Forwards Maestro launch arguments (intent extras) to the JS app as initial props
override fun getLaunchOptions(): Bundle =
Bundle().apply {
putBoolean(
"showScrollOffset",
intent?.getBooleanExtra("showScrollOffset", false) ?: false,
)
}
}
}
12 changes: 12 additions & 0 deletions apps/example/ios/EnrichedTextInputExample/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,21 @@ class SceneDelegate: RCTDefaultReactNativeFactoryDelegate, UIWindowSceneDelegate
reactNativeFactory?.devMenuConfiguration = devMenuConfiguration
#endif

// Forwards Maestro launch arguments to the JS app as initial props.
// Maestro passes them as plain `key value` process arguments (no leading `-`),
// so they don't end up in UserDefaults.
let arguments = ProcessInfo.processInfo.arguments
let showScrollOffset = zip(arguments, arguments.dropFirst()).contains {
$0 == "showScrollOffset" && $1 == "true"
}
let initialProperties: [AnyHashable: Any] = [
"showScrollOffset": showScrollOffset
]

reactNativeFactory?.startReactNative(
withModuleName: "EnrichedTextInputExample",
in: window,
initialProperties: initialProperties,
connectionOptions: connectionOptions
)

Expand Down
8 changes: 7 additions & 1 deletion apps/example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import { EnrichedTextScreen } from './screens/EnrichedTextScreen';

type Screen = 'dev' | 'test' | 'enrichedText';

export default function App() {
interface AppProps {
// Passed by Maestro as a launch argument, see MainActivity and SceneDelegate
showScrollOffset?: boolean;
}

export default function App({ showScrollOffset = false }: AppProps) {
const [screen, setScreen] = useState<Screen>('dev');

if (screen === 'test') {
return (
<TestScreen
showScrollOffset={showScrollOffset}
onSwitch={() => setScreen('dev')}
onSwitchEnrichedText={() => setScreen('enrichedText')}
/>
Expand Down
9 changes: 2 additions & 7 deletions apps/example/src/components/ModalShell.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { type FC, type ReactNode } from 'react';
import {
KeyboardAvoidingView,
Modal,
Platform,
StyleSheet,
} from 'react-native';
import { KeyboardAvoidingView, Modal, StyleSheet } from 'react-native';

interface ModalShellProps {
isOpen: boolean;
Expand All @@ -21,7 +16,7 @@ export const ModalShell: FC<ModalShellProps> = ({
<Modal visible={isOpen} animationType="slide" transparent>
<KeyboardAvoidingView
style={styles.container}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
behavior="padding"
Comment thread
exploIF marked this conversation as resolved.
Resolved
enabled={avoidKeyboard}
>
{children}
Expand Down
Loading
Loading