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: fire onScroll from props in KeyboardAwareScrollView #339

Merged
merged 2 commits into from
Jan 20, 2024

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Jan 20, 2024

📜 Description

Fire onScroll from props in KeyboardAwareScrollView.

💡 Motivation and Context

Initially I wanted to achieve that as runOnJS(props.onScroll)({ nativeEvent: e }). But in this case I'm getting:

Argument of type '{ nativeEvent: ReanimatedScrollEvent; }' is not assignable to parameter of type 'NativeSyntheticEvent<NativeScrollEvent>'.
  Type '{ nativeEvent: ReanimatedScrollEvent; }' is missing the following properties from type 'NativeSyntheticEvent<NativeScrollEvent>': currentTarget, target, bubbles, cancelable, and 10 more.ts(2345)

And it's really incorrect, because several properties will be missing and js-based handler (not based on Animated.event) may not read expected properties (such as target etc.).

So I wanted to pass onScroll handler from reanimated as onScrollReanimated property. In this case onScroll will be passed from rest props and will be fired correctly.

Closes #337

📢 Changelog

JS

  • changed component documentation to multiline comment;
  • pass onScroll (as rest) to ScrollView.

🤔 How Has This Been Tested?

Tested manually on iPhone 15 Pro.

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko added 🐛 bug Something isn't working 📚 components Anything related to the exported components of this library labels Jan 20, 2024
@kirillzyusko kirillzyusko self-assigned this Jan 20, 2024
Copy link
Contributor

📊 Package size report

Current size Target Size Difference
113250 bytes 113786 bytes -536 bytes 📉

@kirillzyusko kirillzyusko marked this pull request as ready for review January 20, 2024 12:10
@kirillzyusko kirillzyusko merged commit 299d246 into main Jan 20, 2024
6 checks passed
@kirillzyusko kirillzyusko deleted the fix/337-fire-on-scroll branch January 20, 2024 12:23
kirillzyusko added a commit that referenced this pull request Apr 5, 2024
## 📜 Description

Fixed firing of `onScroll` in `KeyboardAwareScrollView`

## 💡 Motivation and Context

Initially it was fixed in
#339
and I'm sure it was working 😅

However it looks like in current setup (RN 0.73, REA 3.8.0) such way is
not working and `onScroll` property still gets ignored 😔

So in this PR I followed a different path: initially I wanted to fire
this handler via `runOnJS`, but we can not follow a full signature of
the method, since REA has only `nativeEvent` property (and indeed in
this case some properties would be simply missing).

The different path was to update a shared value from JS thread and call
a callback as usually - it fixes a problem in old code and in a new, so
for now this approach looks decent 👍

Let's see how it works in a wild life 👀

Also in this PR I'm changing content of `tea.yaml` - it should be done
in separate PR, but I don't want to open another PR just to fix quotes,
so decided to merge everything in a single one 🙈

Closes
#337

## 📢 Changelog

### JS

- fire `onScroll` in callback;
- react on scroll position change in JS thread.

### FS (file system)

- added single quotes `'` for `tea.yaml`;

## 🤔 How Has This Been Tested?

Tested manually on iPhone 15 Pro.

## 📸 Screenshots (if appropriate):

<img width="474" alt="image"
src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/11896adc-3fdd-4ab3-acf9-9f32f27e787c">

## 📝 Checklist

- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
@kirillzyusko kirillzyusko added the KeyboardAwareScrollView 📜 Anything related to KeyboardAwareScrollView component label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 📚 components Anything related to the exported components of this library KeyboardAwareScrollView 📜 Anything related to KeyboardAwareScrollView component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onScroll on KeyboardAwareScrollView is not fired
1 participant