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

[RNMobile] another approach to fix jumping toolbar #24414

Merged
merged 5 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/block-library/src/button/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ class ButtonEdit extends Component {
__unstableMobileNoFocusOnMount={ ! isSelected }
selectionColor={ textColor }
onBlur={ () => {
this.onToggleButtonFocus( false );
dratwas marked this conversation as resolved.
Show resolved Hide resolved
this.onSetMaxWidth();
} }
onReplace={ onReplace }
Expand Down
86 changes: 83 additions & 3 deletions packages/components/src/mobile/keyboard-avoiding-view/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,99 @@
*/
import {
KeyboardAvoidingView as IOSKeyboardAvoidingView,
Animated,
Keyboard,
Dimensions,
View,
} from 'react-native';
import SafeArea from 'react-native-safe-area';

/**
* WordPress dependencies
*/
import { useEffect, useRef } from '@wordpress/element';
import { useResizeObserver } from '@wordpress/compose';

/**
* Internal dependencies
*/
import styles from './styles.scss';

const AnimatedKeyboardAvoidingView = Animated.createAnimatedComponent(
IOSKeyboardAvoidingView
);

const MIN_HEIGHT = 44;

export const KeyboardAvoidingView = ( {
parentHeight,
style,
withAnimatedHeight = false,
...otherProps
} ) => {
const [ resizeObserver, sizes ] = useResizeObserver();
const { height = 0 } = sizes || {};

const animatedHeight = useRef( new Animated.Value( MIN_HEIGHT ) ).current;

export const KeyboardAvoidingView = ( { parentHeight, ...otherProps } ) => {
const { height: fullHeight } = Dimensions.get( 'window' );
const keyboardVerticalOffset = fullHeight - parentHeight;

useEffect( () => {
Keyboard.addListener( 'keyboardWillShow', onKeyboardWillShow );
Keyboard.addListener( 'keyboardWillHide', onKeyboardWillHide );
return () => {
Keyboard.removeListener( 'keyboardWillShow', onKeyboardWillShow );
Keyboard.removeListener( 'keyboardWillHide', onKeyboardWillHide );
};
}, [] );

function onKeyboardWillShow( { endCoordinates } ) {
SafeArea.getSafeAreaInsetsForRootView().then( ( result ) => {
animatedHeight.setValue(
endCoordinates.height +
MIN_HEIGHT -
result.safeAreaInsets.bottom
);
} );
}

function onKeyboardWillHide( { duration } ) {
animate( duration );
}

function animate( duration ) {
lukewalczak marked this conversation as resolved.
Show resolved Hide resolved
Animated.timing( animatedHeight, {
toValue: MIN_HEIGHT,
duration,
useNativeDriver: false,
} ).start();
}

return (
<IOSKeyboardAvoidingView
<AnimatedKeyboardAvoidingView
{ ...otherProps }
behavior="padding"
keyboardVerticalOffset={ keyboardVerticalOffset }
/>
style={
withAnimatedHeight
? [ style, { height: animatedHeight } ]
: style
}
>
<View
style={ [
{
top: -height + MIN_HEIGHT,
},
styles.animatedChildStyle,
! withAnimatedHeight && styles.defaultChildStyle,
] }
>
{ resizeObserver }
{ otherProps.children }
</View>
</AnimatedKeyboardAvoidingView>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.animatedChildStyle {
position: absolute;
width: 100%;
}

.defaultChildStyle {
height: 100%;
top: 0;
}
1 change: 1 addition & 0 deletions packages/edit-post/src/components/layout/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class Layout extends Component {
<KeyboardAvoidingView
parentHeight={ this.state.rootViewHeight }
style={ toolbarKeyboardAvoidingViewStyle }
withAnimatedHeight
>
{ isTemplatePickerAvailable && (
<__experimentalPageTemplatePicker
Expand Down