Skip to content

Commit

Permalink
Mobile - KeyboardAwareFlatList - Remove usage of isKeboardVisible sin…
Browse files Browse the repository at this point in the history
…ce we just need to know if there's a keyboard offset set or not. It also removes measureScrollView from the useEffect that listens to device orientation changes
  • Loading branch information
Gerardo committed Mar 31, 2023
1 parent bf36349 commit fdda82f
Showing 1 changed file with 4 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ export const KeyboardAwareFlatList = ( {
const { height: windowHeight, width: windowWidth } = useWindowDimensions();
const isLandscape = windowWidth >= windowHeight;

const [ isKeyboardVisible, keyboardOffset ] =
useKeyboardOffset( scrollEnabled );
const [ keyboardOffset ] = useKeyboardOffset( scrollEnabled );

const [ currentCaretData ] = useTextInputCaretPosition( scrollEnabled );

Expand All @@ -62,23 +61,13 @@ export const KeyboardAwareFlatList = ( {
useCallback(
async ( caret ) => {
const textInputOffset = await getTextInputOffset( caret );
const isKeyboardVisibleWithOffset =
isKeyboardVisible && keyboardOffset !== 0;
const hasTextInputOffset = textInputOffset !== null;

if (
( isKeyboardVisibleWithOffset && hasTextInputOffset ) ||
( ! isKeyboardVisible && hasTextInputOffset )
) {
if ( hasTextInputOffset ) {
scrollToTextInputOffset( caret, textInputOffset );
}
},
[
getTextInputOffset,
isKeyboardVisible,
keyboardOffset,
scrollToTextInputOffset,
]
[ getTextInputOffset, scrollToTextInputOffset ]
),
200,
{ leading: false }
Expand All @@ -92,12 +81,7 @@ export const KeyboardAwareFlatList = ( {
// need to be re-calculated.
useEffect( () => {
scrollViewMeasurements.current = null;
// Only re-caculate them if there's an existing value
// as it should be set when the ScrollView content changes.
if ( scrollViewMeasurements.current ) {
measureScrollView();
}
}, [ isLandscape, measureScrollView ] );
}, [ isLandscape ] );

const scrollHandler = useAnimatedScrollHandler( {
onScroll: ( event ) => {
Expand Down

0 comments on commit fdda82f

Please sign in to comment.