Skip to content
This repository was archived by the owner on Jul 27, 2021. It is now read-only.

Commit fd35c74

Browse files
author
baijunjie
committed
v1.9.0
fixed #48
1 parent 6370260 commit fd35c74

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ _onContentSizeChange = ({nativeEvent:event}) => {
9898

9999
| Property | Type | Default | Description |
100100
| ----------------------- | -------- | ------- | ---------------------------------------- |
101+
| `topOffset` | `number` | `undefined` | The offset of the `InputScrollView` relative to the top of the window. When the screen contains `TopBar`, it is usually set to the height of `TopBar`. If not explicitly set, the program will automatically determine, but may cause problems [issues#43](https://github.com/baijunjie/react-native-input-scroll-view/issues/43)|
101102
| `keyboardOffset` | `number` | `40` | When automatic adjustment, the cursor relative to the top of the keyboard offset. |
102103
| `multilineInputStyle` | `Style` | `null` | If your multiline `TextInput` has a specific style, to ensure that the cursor can be accurately adjusted to the top of the keyboard, this is set as a multiline `TextInput` style, The style attributes that mainly include `fontSize``fontFamily``lineHeight` etc. affect the position of the cursor. **Be careful not to include `width` and `height`**. |
103104
| `useAnimatedScrollView` | `bool` | `false` | Replace regular `ScrollView` component with `Animated.ScrollView` component. |

__test__/react-native-input-scroll-view/index.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ if (isIOS) {
6565

6666
export default class extends PureComponent {
6767
static propTypes = {
68+
topOffset: PropTypes.number,
6869
keyboardOffset: PropTypes.number,
6970
multilineInputStyle: PropTypes.oneOfType([
7071
PropTypes.object,
@@ -93,8 +94,8 @@ export default class extends PureComponent {
9394
this._curFocus = null;
9495
this._measureCallback = null;
9596
this._keyboardShow = false;
96-
this._topOffset = 0;
9797
this._inputInfoMap = {};
98+
this._topOffset = this.props.topOffset;
9899

99100
this._addListener();
100101
this._extendScrollViewFunc();
@@ -106,6 +107,7 @@ export default class extends PureComponent {
106107

107108
render() {
108109
const {
110+
topOffset,
109111
keyboardOffset,
110112
multilineInputStyle,
111113
useAnimatedScrollView,
@@ -265,12 +267,18 @@ export default class extends PureComponent {
265267
this._root = this._root._component;
266268
}
267269

268-
setTimeout(() => {
270+
const getTopOffset = () => {
271+
this.props.topOffset === undefined &&
269272
this._root._innerViewRef &&
270273
this._root._innerViewRef.measureInWindow((x, y) => {
271274
this._topOffset = y;
272275
});
273-
});
276+
};
277+
278+
setTimeout(getTopOffset);
279+
// 如果屏幕是带动画进入,那么初次获取的位置偏移量并不准确,需要等动画听指挥重新计算
280+
// 这里暂定等待时间为 1000 毫秒
281+
setTimeout(getTopOffset, 1000);
274282
};
275283

276284
_scrollToKeyboardRequest = () => {

index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
import { ScrollViewProperties, TextStyle, ScrollView } from 'react-native';
33

44
export interface InputScrollViewProps extends ScrollViewProperties {
5+
readonly topOffset?: number;
56
readonly keyboardOffset?: number;
67
readonly multilineInputStyle?: TextStyle;
78
readonly useAnimatedScrollView?: boolean;

index.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ if (isIOS) {
6565

6666
export default class extends PureComponent {
6767
static propTypes = {
68+
topOffset: PropTypes.number,
6869
keyboardOffset: PropTypes.number,
6970
multilineInputStyle: PropTypes.oneOfType([
7071
PropTypes.object,
@@ -93,8 +94,8 @@ export default class extends PureComponent {
9394
this._curFocus = null;
9495
this._measureCallback = null;
9596
this._keyboardShow = false;
96-
this._topOffset = 0;
9797
this._inputInfoMap = {};
98+
this._topOffset = this.props.topOffset;
9899

99100
this._addListener();
100101
this._extendScrollViewFunc();
@@ -106,6 +107,7 @@ export default class extends PureComponent {
106107

107108
render() {
108109
const {
110+
topOffset,
109111
keyboardOffset,
110112
multilineInputStyle,
111113
useAnimatedScrollView,
@@ -265,12 +267,18 @@ export default class extends PureComponent {
265267
this._root = this._root._component;
266268
}
267269

268-
setTimeout(() => {
270+
const getTopOffset = () => {
271+
this.props.topOffset === undefined &&
269272
this._root._innerViewRef &&
270273
this._root._innerViewRef.measureInWindow((x, y) => {
271274
this._topOffset = y;
272275
});
273-
});
276+
};
277+
278+
setTimeout(getTopOffset);
279+
// 如果屏幕是带动画进入,那么初次获取的位置偏移量并不准确,需要等动画听指挥重新计算
280+
// 这里暂定等待时间为 1000 毫秒
281+
setTimeout(getTopOffset, 1000);
274282
};
275283

276284
_scrollToKeyboardRequest = () => {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-input-scroll-view",
3-
"version": "1.8.4",
3+
"version": "1.9.0",
44
"description": "Perfect TextInput ScrollView",
55
"main": "index.js",
66
"types": "index.d.ts",

中文说明.md

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ _onContentSizeChange = ({nativeEvent:event}) => {
9797

9898
| 属性 | 类型 | 默认值 | 描述 |
9999
| ----------------------- | -------- | ------- | ---------------------------------------- |
100+
| `topOffset` | `number` | `undefined` | `InputScrollView` 相对于窗口顶部的偏移量。当屏幕包含 `TopBar` 时,通常设置为 `TopBar` 的高度。如果未明确设置,程序会自动判断,但是可能会引起问题 [issues#43](https://github.com/baijunjie/react-native-input-scroll-view/issues/43)|
100101
| `keyboardOffset` | `number` | `40` | 当自动调整时,光标相对于键盘顶部的偏移量。 |
101102
| `multilineInputStyle` | `Style` | `null` | 如果你的多行输入框有特定的样式,那么为了光标能够精准调整到键盘上方,应该将多行文本的样式也设置在这里,主要包含 `fontSize``fontFamily``lineHeight` 等会影响到光标位置的样式属性。**注意,不要包含 `width``height`**|
102103
| `useAnimatedScrollView` | `bool` | `false` |`Animated.ScrollView` 组件替换 `ScrollView` 组件。 |

0 commit comments

Comments
 (0)