Skip to content

Commit

Permalink
Revert "[RNMobile] another approach to fix jumping toolbar (#24414)"
Browse files Browse the repository at this point in the history
This reverts commit 6604d96.
  • Loading branch information
lukewalczak authored Aug 14, 2020
1 parent d5a8822 commit d15ae34
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 89 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/button/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class ButtonEdit extends Component {
__unstableMobileNoFocusOnMount={ ! isSelected }
selectionColor={ textColor }
onBlur={ () => {
this.onToggleButtonFocus( false );
this.onSetMaxWidth();
} }
onReplace={ onReplace }
Expand Down
82 changes: 3 additions & 79 deletions packages/components/src/mobile/keyboard-avoiding-view/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,19 @@
*/
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 } ) {
Animated.timing( animatedHeight, {
toValue: MIN_HEIGHT,
duration,
useNativeDriver: false,
} ).start();
}

return (
<AnimatedKeyboardAvoidingView
<IOSKeyboardAvoidingView
{ ...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

This file was deleted.

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

0 comments on commit d15ae34

Please sign in to comment.