Skip to content
This repository was archived by the owner on Jul 9, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,8 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[untyped]
<PROJECT_ROOT>/node_modules/react-native-keyboard-aware-scroll-view/.*

[version]
^0.67.0
^0.67.1
6 changes: 6 additions & 0 deletions __mocks__/styleMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ module.exports = {
blockText: {
minHeight: 50,
},
container: {
height: 44,
},
toolbar: {
height: 44,
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"react": "16.6.1",
"react-native": "0.57.5",
"react-native-hr": "git+https://github.com/Riglerr/react-native-hr.git#2d01a5cf77212d100e8b99e0310cce5234f977b3",
"react-native-keyboard-aware-scroll-view": "^0.8.0",
"react-native-modal": "^6.5.0",
"react-native-recyclerview-list": "git+https://github.com/wordpress-mobile/react-native-recyclerview-list.git#v1.0.0",
"react-native-svg": "git+https://github.com/wordpress-mobile/react-native-svg.git#2b76859a986d35d741c9160aaad54aa46f268c6e",
Expand Down
56 changes: 41 additions & 15 deletions src/block-management/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
import React from 'react';
import { isEqual } from 'lodash';

import { Text, View, FlatList, Keyboard, LayoutChangeEvent, SafeAreaView } from 'react-native';
import { Text, View, Keyboard, LayoutChangeEvent, SafeAreaView } from 'react-native';
import BlockHolder from './block-holder';
import { InlineToolbarActions } from './inline-toolbar';
import type { BlockType } from '../store/types';
import styles from './block-manager.scss';
import inlineToolbarStyles from './inline-toolbar/style.scss';
import toolbarStyles from './block-toolbar.scss';
import BlockPicker from './block-picker';
import HTMLTextInput from '../components/html-text-input';
import BlockToolbar from './block-toolbar';
import KeyboardAvoidingView from '../components/keyboard-avoiding-view';

Copy link
Copy Markdown
Contributor

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.

import KeyboardAwareFlatList from '../components/keyboard-aware-flat-list';

// Gutenberg imports
import { withDispatch, withSelect } from '@wordpress/data';
Expand Down Expand Up @@ -64,6 +67,10 @@ export class BlockManager extends React.Component<PropsType, StateType> {
constructor( props: PropsType ) {
super( props );

( this: any ).renderItem = this.renderItem.bind( this );
( this: any ).shouldFlatListPreventAutomaticScroll = this.shouldFlatListPreventAutomaticScroll.bind( this );
( this: any ).keyExtractor = this.keyExtractor.bind( this );

const blocks = props.blocks.map( ( block ) => {
const newBlock = { ...block };
newBlock.focused = props.isBlockSelected( block.clientId );
Expand Down Expand Up @@ -208,33 +215,52 @@ export class BlockManager extends React.Component<PropsType, StateType> {
this.props.replaceBlock( clientId, block );
}

shouldFlatListPreventAutomaticScroll() {
return this.state.blockTypePickerVisible;
}

keyExtractor( item: Object ) {
return item.clientId;
}

renderList() {
// TODO: we won't need this. This just a temporary solution until we implement the RecyclerViewList native code for iOS
// And fix problems with RecyclerViewList on Android
const list = (
<FlatList
<KeyboardAwareFlatList
blockToolbarHeight={ toolbarStyles.container.height }
innerToolbarHeight={ inlineToolbarStyles.toolbar.height }
parentHeight={ this.state.rootViewHeight }
keyboardShouldPersistTaps="always"
style={ styles.list }
data={ this.state.blocks }
extraData={ { refresh: this.state.refresh } }
keyExtractor={ ( item ) => item.clientId }
renderItem={ this.renderItem.bind( this ) }
keyExtractor={ this.keyExtractor }
renderItem={ this.renderItem }
shouldPreventAutomaticScroll={ this.shouldFlatListPreventAutomaticScroll }
/>
);
return (
<KeyboardAvoidingView style={ { flex: 1 } } parentHeight={ this.state.rootViewHeight }>
<View style={ { flex: 1 } } >
<DefaultBlockAppender rootClientId={ this.props.rootClientId } />
{ list }
<BlockToolbar
onInsertClick={ () => {
this.showBlockTypePicker( true );
} }
onKeyboardHide={ () => {
this.onKeyboardHide();
} }
showKeyboardHideButton={ this.state.isKeyboardVisible }
/>
</KeyboardAvoidingView>
<SafeAreaView>
<View style={ { height: toolbarStyles.container.height } } />
</SafeAreaView>
<KeyboardAvoidingView
style={ styles.blockToolbarKeyboardAvoidingView }
parentHeight={ this.state.rootViewHeight } >
<BlockToolbar
onInsertClick={ () => {
this.showBlockTypePicker( true );
} }
onKeyboardHide={ () => {
this.onKeyboardHide();
} }
showKeyboardHideButton={ this.state.isKeyboardVisible }
/>
</KeyboardAvoidingView>
</View>
);
}

Expand Down
7 changes: 7 additions & 0 deletions src/block-management/block-manager.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@
flex-direction: row;
background-color: white;
}

.blockToolbarKeyboardAvoidingView {
position: absolute;
bottom: 0;
right: 0;
left: 0;
}
23 changes: 23 additions & 0 deletions src/components/keyboard-aware-flat-list.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @format
* @flow
*/
import { FlatList, KeyboardAvoidingView } from 'react-native';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @pinarol . Late one...
We didn't use KeyboardAvoidingView from 'rect-native' but we had our abstract presentation of it in components/keyboard-avoiding-view.ios.js and components/keyboard-avoiding-view.android.js

That was introduced to fix the problem with toolbar visibility after orientation change in WPiOS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the heads up @marecar3 addressing that in #397


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;
65 changes: 65 additions & 0 deletions src/components/keyboard-aware-flat-list.ios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @format

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpicking:
Can we have the import bellow those comments?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 react-native-keyboard-aware-scroll-view"
I think that happens because I added react-native-keyboard-aware-scroll-view to flowconfig ignore list because flow was trying to validate library source code as well. if there's another solution to this I can apply that happily I just couldn't find any.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hypest offered a new solution and I've pushed a new commit for it 4254072 It is so much better this way 🎉

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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;
18 changes: 13 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3080,11 +3080,6 @@ escodegen@^1.9.1:
optionalDependencies:
source-map "~0.6.1"

eslint-config-wordpress@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/eslint-config-wordpress/-/eslint-config-wordpress-2.0.0.tgz#5201206c6964d648315232edf6dfbd2e925e4cd6"
integrity sha1-UgEgbGlk1kgxUjLt9t+9LpJeTNY=

eslint-plugin-flowtype@^2.46.1:
version "2.50.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.50.3.tgz#61379d6dce1d010370acd6681740fd913d68175f"
Expand Down Expand Up @@ -7316,6 +7311,19 @@ react-native-crypto@^2.0.1:
version "1.1.3"
resolved "git+https://github.com/Riglerr/react-native-hr.git#2d01a5cf77212d100e8b99e0310cce5234f977b3"

react-native-iphone-x-helper@^1.0.3:
version "1.2.0"
resolved "https://registry.yarnpkg.com/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.2.0.tgz#9f8a376eb00bc712115abff4420318a0063fa796"
integrity sha512-xIeTo4s77wwKgBZLVRIZC9tM9/PkXS46Ul76NXmvmixEb3ZwqGdQesR3zRiLMOoIdfOURB6N9bba9po7+x9Bag==

react-native-keyboard-aware-scroll-view@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/react-native-keyboard-aware-scroll-view/-/react-native-keyboard-aware-scroll-view-0.8.0.tgz#00bcaa38c91323913bb7a733059ad2bc4875f88c"
integrity sha512-gPfhgHQI/z7Cc5aeNOEmK0b250QkAeU6V+4oH8EC7mmFneEKn6MAIDjpoiwqt6bV+lFJPABXfx9MtrRmtCeJ/Q==
dependencies:
prop-types "^15.6.2"
react-native-iphone-x-helper "^1.0.3"

react-native-modal@^6.5.0:
version "6.5.0"
resolved "https://registry.yarnpkg.com/react-native-modal/-/react-native-modal-6.5.0.tgz#46220b2289a41597d344c1db17454611b426a758"
Expand Down