diff --git a/README.md b/README.md index e15f8dd..2d52b45 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ Android Support is not perfect, here is the supported list: | `viewIsInsideTabBar` | Yes | | `resetScrollToCoords` | Yes | | `enableAutomaticScroll` | Yes | +| `insetOnly` | Yes | | `extraHeight` | Yes | | `extraScrollHeight` | Yes | | `enableResetScrollToCoords` | Yes | @@ -136,17 +137,18 @@ Android Support is not perfect, here is the supported list: All the `ScrollView`/`FlatList` props will be passed. -| **Prop** | **Type** | **Description** | -| --------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------- | -| `innerRef` | `Function` | Catch the reference of the component. | -| `viewIsInsideTabBar` | `boolean` | Adds an extra offset that represents the `TabBarIOS` height. | -| `resetScrollToCoords` | `Object: {x: number, y: number}` | Coordinates that will be used to reset the scroll when the keyboard hides. | -| `enableAutomaticScroll` | `boolean` | When focus in `TextInput` will scroll the position, default is enabled. | -| `extraHeight` | `number` | Adds an extra offset when focusing the `TextInput`s. | -| `extraScrollHeight` | `number` | Adds an extra offset to the keyboard. Useful if you want to stick elements above the keyboard. | -| `enableResetScrollToCoords` | `boolean` | Lets the user enable or disable automatic resetScrollToCoords. | -| `keyboardOpeningTime` | `number` | Sets the delay time before scrolling to new position, default is 250 | -| `enableOnAndroid` | `boolean` | Enable Android Support | +| **Prop** | **Type** | **Description** | +| --------------------------- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `innerRef` | `Function` | Catch the reference of the component. | +| `viewIsInsideTabBar` | `boolean` | Adds an extra offset that represents the `TabBarIOS` height. | +| `resetScrollToCoords` | `Object: {x: number, y: number}` | Coordinates that will be used to reset the scroll when the keyboard hides. | +| `enableAutomaticScroll` | `boolean` | When focus in `TextInput` will scroll the position, default is enabled. | +| `insetOnly` | `boolean` | Only adds content inset for the keyboard and disables autoScroll. iOS will fit TextInput to the screen if it was visible before keyboard open. Default is false. | +| `extraHeight` | `number` | Adds an extra offset when focusing the `TextInput`s. | +| `extraScrollHeight` | `number` | Adds an extra offset to the keyboard. Useful if you want to stick elements above the keyboard. | +| `enableResetScrollToCoords` | `boolean` | Lets the user enable or disable automatic resetScrollToCoords. | +| `keyboardOpeningTime` | `number` | Sets the delay time before scrolling to new position, default is 250 | +| `enableOnAndroid` | `boolean` | Enable Android Support | ### Methods diff --git a/lib/KeyboardAwareHOC.js b/lib/KeyboardAwareHOC.js index 4bf0ed0..7692e5b 100644 --- a/lib/KeyboardAwareHOC.js +++ b/lib/KeyboardAwareHOC.js @@ -50,6 +50,7 @@ export type KeyboardAwareHOCProps = { }, enableResetScrollToCoords?: boolean, enableAutomaticScroll?: boolean, + insetOnly?: boolean, extraHeight?: number, extraScrollHeight?: number, keyboardOpeningTime?: number, @@ -94,6 +95,7 @@ export type KeyboardAwareHOCOptions = ?{ enableOnAndroid: boolean, contentContainerStyle: ?Object, enableAutomaticScroll: boolean, + insetOnly: boolean, extraHeight: number, extraScrollHeight: number, enableResetScrollToCoords: boolean, @@ -115,6 +117,7 @@ const ScrollIntoViewDefaultOptions: KeyboardAwareHOCOptions = { enableOnAndroid: false, contentContainerStyle: undefined, enableAutomaticScroll: true, + insetOnly: false, extraHeight: _KAM_EXTRA_HEIGHT, extraScrollHeight: 0, enableResetScrollToCoords: true, @@ -169,6 +172,7 @@ function KeyboardAwareHOC( }), enableResetScrollToCoords: PropTypes.bool, enableAutomaticScroll: PropTypes.bool, + insetOnly: PropTypes.bool, extraHeight: PropTypes.number, extraScrollHeight: PropTypes.number, keyboardOpeningTime: PropTypes.number, @@ -186,6 +190,7 @@ function KeyboardAwareHOC( // HOC options are used to init default props, so that these options can be overriden with component props static defaultProps = { enableAutomaticScroll: hocOptions.enableAutomaticScroll, + insetOnly: hocOptions.insetOnly, extraHeight: hocOptions.extraHeight, extraScrollHeight: hocOptions.extraScrollHeight, enableResetScrollToCoords: hocOptions.enableResetScrollToCoords, @@ -361,14 +366,15 @@ function KeyboardAwareHOC( // Keyboard actions _updateKeyboardSpace = (frames: Object) => { + let keyboardSpace: number = + frames.endCoordinates.height + this.props.extraScrollHeight + if (this.props.viewIsInsideTabBar) { + keyboardSpace -= _KAM_DEFAULT_TAB_BAR_HEIGHT + } + this.setState({keyboardSpace}) + // Automatically scroll to focused TextInput - if (this.props.enableAutomaticScroll) { - let keyboardSpace: number = - frames.endCoordinates.height + this.props.extraScrollHeight - if (this.props.viewIsInsideTabBar) { - keyboardSpace -= _KAM_DEFAULT_TAB_BAR_HEIGHT - } - this.setState({ keyboardSpace }) + if (this.props.enableAutomaticScroll && !this.props.insetOnly) { const currentlyFocusedField = TextInput.State.currentlyFocusedField() const responder = this.getScrollResponder() if (!currentlyFocusedField || !responder) { diff --git a/package.json b/package.json index e5f3045..4c1aa8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-keyboard-aware-scroll-view", - "version": "0.9.1", + "version": "0.9.2", "description": "A React Native ScrollView component that resizes when the keyboard appears.", "main": "index.js", "types": "index.d.ts",