-
-
Notifications
You must be signed in to change notification settings - Fork 129
fix: inverted list padding #668
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
lpatrun
wants to merge
4
commits into
kirillzyusko:main
Choose a base branch
from
lpatrun:fix/inverted-list-padding
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -38,6 +38,10 @@ export type KeyboardAwareScrollViewProps = { | |
| enabled?: boolean; | ||
| /** Adjusting the bottom spacing of KeyboardAwareScrollView. Default is `0` */ | ||
| extraKeyboardSpace?: number; | ||
| /** Used if inverted Flatlist/Flashlist is being used */ | ||
| inverted?: boolean; | ||
| /** Ajdusting the offset for the content when keyboard is shown on inverted Flatlist/Flashlist on screen with BottomTab navigation */ | ||
| tabBarHeight?: number; | ||
lpatrun marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** Custom component for `ScrollView`. Default is `ScrollView` */ | ||
| ScrollViewComponent?: React.ComponentType<ScrollViewProps>; | ||
| } & ScrollViewProps; | ||
|
|
@@ -94,6 +98,8 @@ const KeyboardAwareScrollView = forwardRef< | |
| extraKeyboardSpace = 0, | ||
| ScrollViewComponent = Reanimated.ScrollView, | ||
| snapToOffsets, | ||
| inverted = false, | ||
| tabBarHeight = 0, | ||
| ...rest | ||
| }, | ||
| ref, | ||
|
|
@@ -349,18 +355,20 @@ const KeyboardAwareScrollView = forwardRef< | |
| ); | ||
|
|
||
| const view = useAnimatedStyle( | ||
| () => | ||
| enabled | ||
| () => { | ||
| const invertedOffset = inverted ? -tabBarHeight : 0; | ||
| return enabled | ||
| ? { | ||
| // animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused) | ||
| // this happens because the layout recalculates on every frame. To avoid this we slightly increase padding | ||
| // by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation | ||
| // from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout | ||
| // re-calculation on every animation frame and it helps to achieve smooth animation. | ||
| // see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342 | ||
| paddingBottom: currentKeyboardFrameHeight.value + 1, | ||
| paddingBottom: currentKeyboardFrameHeight.value + invertedOffset + 1, | ||
|
||
| } | ||
| : {}, | ||
| : {} | ||
| }, | ||
| [enabled], | ||
| ); | ||
|
|
||
|
|
@@ -371,8 +379,9 @@ const KeyboardAwareScrollView = forwardRef< | |
| scrollEventThrottle={16} | ||
| onLayout={onScrollViewLayout} | ||
| > | ||
| {inverted ? <Reanimated.View style={view} /> : null} | ||
| {children} | ||
| <Reanimated.View style={view} /> | ||
| {!inverted ? <Reanimated.View style={view} /> : null} | ||
| </ScrollViewComponent> | ||
| ); | ||
| }, | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this property can be derived from
styleproperty?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I am missing how to call style, but when I call it as is in the component, I get
"Cannot find name 'style'."
and in rest.style I have only
"style": {"backgroundColor": "#FFFFFF", "flex": 1}}so ni scaleY.But this inverted prop should be ok because it is a Flatlist/Flashlist prop. Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lpatrun can you show me how do you use
FlatListandKeyboardAwareScrollView?I assumed it would be something like that:
And here (if I understand correctly)
props.styleshould containtransformproperty (it should be injected byFlatList). Or no? 🙈Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the code from the app
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @lpatrun
I'll check it today! ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lpatrun
I added this code to
KeyboardAwareScrollView(it has TS errors):And this code I used for testing:
And it seems to work fine:
Can you check on your side again?