Skip to content
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

Fix calling onScroll multiple times with incorrect y-axis offset #144

Merged
merged 3 commits into from
Jan 31, 2024

Conversation

tomekzaw
Copy link
Collaborator

@tomekzaw tomekzaw commented Jan 31, 2024

Details

Fixes #139. Fixes #136.

This PR fixes the incorrect behavior of MarkdownTextInput when maxHeight is set, in particular:

  1. eliminates emitting onLayout events on each keypress with incorrect y-axis offset
  2. restores automatically scrolling to the next line once newline character is appended

Source: https://stackoverflow.com/a/43270032/23325954

Related Issues

GH_LINK

Manual Tests

Linked PRs

@tomekzaw tomekzaw requested a review from robertKozik January 31, 2024 13:09
@robertKozik
Copy link
Collaborator

Also fixes #136

proof on example app
Screen.Recording.2024-01-31.at.15.55.49.mov

@tomekzaw
Copy link
Collaborator Author

Repro for #136 and #139 on 2fa000c (using TextKit 1):

<MarkdownTextInput
  multiline
  autoCapitalize="none"
  value={value}
  onChangeText={setValue}
  style={[styles.input, {maxHeight: 120}]}
  onScroll={(e) => console.log(e.nativeEvent.contentOffset)}
  ref={ref}
/>
❌ Incorrect onLayout events are emitted on each keypress ❌ Content is not scrolled automatically when appending a newline ✅ Content offset stays correct on each keypress
Screen.Recording.2024-01-31.at.18.59.15.mov
Screen.Recording.2024-01-31.at.18.56.45.mov
Screen.Recording.2024-01-31.at.19.14.32.mov

After commenting out _textView.layoutManager (effectively using TextKit 2 instead of TextKit 1):

✅ Correct onLayout events are emitted only when needed ✅ Content is scrolled automatically when appending a newline ❌ Content offset alternates on each keypress
Screen.Recording.2024-01-31.at.19.06.11.mov
Screen.Recording.2024-01-31.at.19.06.33.mov
Screen.Recording.2024-01-31.at.19.12.47.mov

After restoring _textView.layoutManager and adding layoutManager.allowsNonContiguousLayout = NO;:

✅ Correct onLayout events are emitted only when needed ✅ Content is scrolled automatically when appending a newline ✅ Content offset stays correct on each keypress
Screen.Recording.2024-01-31.at.19.19.58.mov
Screen.Recording.2024-01-31.at.19.22.41.mov
Screen.Recording.2024-01-31.at.19.19.28.mov

Copy link
Collaborator

@robertKozik robertKozik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 🎉 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants