Repository navigation
Fix scroll position on iOS #387
Changes from all commits
f04ee5b
4bf5833
1027a9f
fa5e9a7
253dcfe
5e6d209
a10cf88
689023d
8519695
7c1864f
98bd903
cdaa613
15a6265
401d698
4254072
f14772b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,10 @@ module.exports = { | |
| blockText: { | ||
| minHeight: 50, | ||
| }, | ||
| container: { | ||
| height: 44, | ||
| }, | ||
| toolbar: { | ||
| height: 44, | ||
| }, | ||
| }; | ||
| +9 −1 | packages/editor/src/components/plain-text/index.native.js | |
| +6 −1 | packages/editor/src/components/rich-text/index.native.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * @format | ||
| * @flow | ||
| */ | ||
| import { FlatList, KeyboardAvoidingView } from 'react-native'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @pinarol . Late one... That was introduced to fix the problem with toolbar visibility after orientation change in WPiOS.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| type PropsType = { | ||
| ...FlatList.propTypes, | ||
| shouldPreventAutomaticScroll: void => boolean, | ||
| parentHeight: number, | ||
| blockToolbarHeight: number, | ||
| innerToolbarHeight: number, | ||
| } | ||
|
|
||
| const KeyboardAwareFlatList = ( props: PropsType ) => { | ||
| return ( | ||
| <KeyboardAvoidingView style={ { flex: 1 } }> | ||
| <FlatList { ...props } /> | ||
| </KeyboardAvoidingView> | ||
| ); | ||
| }; | ||
|
|
||
| export default KeyboardAwareFlatList; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** | ||
| * @format | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small nitpicking:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put this here as a solution to flow error "Cannot resolve module
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, that makes sense. In that case can we put a small comment explaining that? :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great solution! 😁 |
||
| * @flow | ||
| */ | ||
| import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'; | ||
| import React from 'react'; | ||
| import { FlatList, Dimensions } from 'react-native'; | ||
|
|
||
| type PropsType = { | ||
| ...FlatList.propTypes, | ||
| shouldPreventAutomaticScroll: void => boolean, | ||
| parentHeight: number, | ||
| blockToolbarHeight: number, | ||
| innerToolbarHeight: number, | ||
| } | ||
|
|
||
| const KeyboardAwareFlatList = ( props: PropsType ) => { | ||
| const { | ||
| parentHeight, | ||
| blockToolbarHeight, | ||
| innerToolbarHeight, | ||
| shouldPreventAutomaticScroll, | ||
| ...listProps | ||
| } = props; | ||
| const { height: fullHeight } = Dimensions.get( 'window' ); | ||
| const keyboardVerticalOffset = fullHeight - parentHeight; | ||
| const blockHolderPadding = 8; | ||
| const extraScrollHeight = blockToolbarHeight + innerToolbarHeight + blockHolderPadding + keyboardVerticalOffset; | ||
|
|
||
| return ( | ||
| <KeyboardAwareScrollView | ||
| style={ { flex: 1 } } | ||
| keyboardDismissMode={ 'none' } | ||
| enableResetScrollToCoords={ false } | ||
| keyboardShouldPersistTaps={ 'handled' } | ||
| extraScrollHeight={ extraScrollHeight } | ||
| extraHeight={ 0 } | ||
| innerRef={ ( ref ) => { | ||
| ( this: any ).scrollViewRef = ref; | ||
| } } | ||
| onKeyboardWillHide={ () => { | ||
| ( this: any ).keyboardWillShowIndicator = false; | ||
| } } | ||
| onKeyboardDidHide={ () => { | ||
| setTimeout( () => { | ||
| if ( ! ( this: any ).keyboardWillShowIndicator && | ||
| ( this: any ).latestContentOffsetY !== undefined && | ||
| ! shouldPreventAutomaticScroll() ) { | ||
| // Reset the content position if keyboard is still closed | ||
| ( this: any ).scrollViewRef.props.scrollToPosition( 0, ( this: any ).latestContentOffsetY, true ); | ||
| } | ||
| }, 50 ); | ||
| } } | ||
| onKeyboardWillShow={ () => { | ||
| ( this: any ).keyboardWillShowIndicator = true; | ||
| } } | ||
| onScroll={ ( event: Object ) => { | ||
| ( this: any ).latestContentOffsetY = event.nativeEvent.contentOffset.y; | ||
| } } > | ||
| <FlatList { ...listProps } /> | ||
| </KeyboardAwareScrollView> | ||
| ); | ||
| }; | ||
|
|
||
| export default KeyboardAwareFlatList; | ||
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.
Hey @pinarol , here we are importing from our file.