Repository navigation
@relextm19/scroll position #850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
relextm19
wants to merge
34
commits into
main
Choose a base branch
from
@relextm19/scroll-position
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
beb0696
feat: add scroll event throtling on web
da69d5f
refactor: changed the throttle ref to a number not an object
cff0e77
Merge branch 'main' of https://github.com/software-mansion/react-nati…
a29b77f
feat: add onScroll on ios
4aa81bf
fix: fix the layout scroll loop
746be5b
refactor: add handler for debuging scrollEvent in example app
8c54bbc
refactor: change the import path for onScrollEvent
fe40d4c
feat: added onScroll on android
b953d35
feat(web): add e2e tests
73ce67a
feat: more towards e2e test
ad95c50
feat(mobile): add more cases to tests
0a2ba65
fix(android): set input min height to avoid an unwanted scroll
0f1bcd0
fix: fix the tests on android
31b11c5
merge main
cbb9979
refactor: restore podfile.lock
5af689d
fix: restore podfile.lock again
e1d8f23
fix: fix the lint issues
2e5d181
refactor: remove throtling to behave more like react native
b494dcd
refactor: removed the helper on android to match the code on other pl…
137db01
Merge branch 'main' of https://github.com/software-mansion/react-nati…
bdd7812
feat: change mobile scroll tests
relextm19 4007cb3
fix(android): fix bug in android scroll event emission
relextm19 a9ef2bc
refactor: more suiting comment
relextm19 ce0bc6f
fix(web): stop react from useless rerendering
relextm19 367e352
feat: add docs for onScroll
relextm19 60c7091
feat(ios): only emmit scrollEvent when contentOffset changes
relextm19 8561157
Merge branch 'main' of https://github.com/software-mansion/react-nati…
relextm19 91cca3a
fix(ios): lint fix
relextm19 4a30f60
feat: only calculate scroll offset if we have a handler
relextm19 17fe873
fix: fix lint warning
relextm19 2cdeddd
feat: add update delay in scroll tests
relextm19 3d0ce66
Merge branch 'main' into @relextm19/scroll-position
szydlovsky 2ff17fd
Merge branch 'main' into @relextm19/scroll-position
szydlovsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
android/src/main/java/com/swmansion/enriched/textinput/events/OnInputScrollEvent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.