Skip to content

Commit ecbdfd7

Browse files
author
joseph kim
committed
Merge branch 'master' into ancestor_check
# Conflicts: # lib/KeyboardAwareMixin.js
2 parents 97fc6a6 + 160974f commit ecbdfd7

File tree

5 files changed

+246
-20
lines changed

5 files changed

+246
-20
lines changed

.eslintrc

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
{
2+
"parser": "babel-eslint",
3+
4+
"ecmaFeatures": {
5+
"jsx": true,
6+
"modules": true,
7+
"experimentalObjectRestSpread": true
8+
},
9+
10+
"env": {
11+
"es6": true,
12+
"jasmine": true,
13+
"node": 1,
14+
},
15+
16+
"plugins": [
17+
"react"
18+
],
19+
20+
"globals": {
21+
"__DEV__": true,
22+
"__dirname": false,
23+
"__fbBatchedBridgeConfig": false,
24+
"cancelAnimationFrame": false,
25+
"clearImmediate": true,
26+
"clearInterval": false,
27+
"clearTimeout": false,
28+
"console": false,
29+
"document": false,
30+
"escape": false,
31+
"exports": false,
32+
"fetch": false,
33+
"global": false,
34+
"jest": false,
35+
"Map": true,
36+
"module": false,
37+
"navigator": false,
38+
"process": false,
39+
"Promise": true,
40+
"requestAnimationFrame": true,
41+
"require": false,
42+
"Set": true,
43+
"setImmediate": true,
44+
"setInterval": false,
45+
"setTimeout": false,
46+
"window": false,
47+
"XMLHttpRequest": false,
48+
"pit": false,
49+
"FormData": true,
50+
},
51+
52+
"rules": {
53+
"comma-dangle": 0,
54+
"no-cond-assign": 1,
55+
"no-console": 0,
56+
"no-constant-condition": 0,
57+
"no-control-regex": 1,
58+
"no-debugger": 1,
59+
"no-dupe-keys": 1,
60+
"no-empty": 0,
61+
"no-empty-character-class": 1,
62+
"no-ex-assign": 1,
63+
"no-extra-boolean-cast": 1,
64+
"no-extra-parens": 0,
65+
"no-extra-semi": 1,
66+
"no-func-assign": 1,
67+
"no-inner-declarations": 0,
68+
"no-invalid-regexp": 1,
69+
"no-negated-in-lhs": 1,
70+
"no-obj-calls": 1,
71+
"no-regex-spaces": 1,
72+
"no-reserved-keys": 0,
73+
"no-sparse-arrays": 1,
74+
"no-unreachable": 1,
75+
"use-isnan": 1,
76+
"valid-jsdoc": 0,
77+
"valid-typeof": 1,
78+
79+
"block-scoped-var": 0,
80+
"complexity": 0,
81+
"consistent-return": 0,
82+
"curly": 1,
83+
"default-case": 0,
84+
"dot-notation": 1,
85+
"eqeqeq": 1,
86+
"guard-for-in": 0,
87+
"no-alert": 1,
88+
"no-caller": 1,
89+
"no-div-regex": 1,
90+
"no-else-return": 0,
91+
"no-labels": 1,
92+
"no-eq-null": 0,
93+
"no-eval": 1,
94+
"no-extend-native": 1,
95+
"no-extra-bind": 1,
96+
"no-fallthrough": 1,
97+
"no-floating-decimal": 1,
98+
"no-implied-eval": 1,
99+
"no-iterator": 1,
100+
"no-lone-blocks": 1,
101+
"no-loop-func": 0,
102+
"no-multi-str": 0,
103+
"no-native-reassign": 0,
104+
"no-new": 1,
105+
"no-new-func": 1,
106+
"no-new-wrappers": 1,
107+
"no-octal": 1,
108+
"no-octal-escape": 1,
109+
"no-proto": 1,
110+
"no-redeclare": 0,
111+
"no-return-assign": 1,
112+
"no-script-url": 1,
113+
"no-self-compare": 1,
114+
"no-sequences": 1,
115+
"no-unused-expressions": 0,
116+
"no-void": 1,
117+
"no-warning-comments": 0,
118+
"no-with": 1,
119+
"radix": 1,
120+
"vars-on-top": 0,
121+
"wrap-iife": 0,
122+
"yoda": 1,
123+
124+
"strict": 0,
125+
126+
"no-catch-shadow": 1,
127+
"no-delete-var": 1,
128+
"no-label-var": 1,
129+
"no-shadow": 1,
130+
"no-shadow-restricted-names": 1,
131+
"no-undef": 2,
132+
"no-undefined": 0,
133+
"no-undef-init": 1,
134+
"no-unused-vars": [1, {"vars": "all", "args": "none"}],
135+
"no-use-before-define": 0,
136+
"handle-callback-err": 1,
137+
"no-mixed-requires": 1,
138+
"no-new-require": 1,
139+
"no-path-concat": 1,
140+
"no-process-exit": 0,
141+
"no-restricted-modules": 1,
142+
"no-sync": 0,
143+
144+
"key-spacing": 0,
145+
"comma-spacing": 0,
146+
"no-multi-spaces": 0,
147+
"brace-style": 0,
148+
"camelcase": 0,
149+
"consistent-this": [1, "self"],
150+
"eol-last": 1,
151+
"func-names": 0,
152+
"func-style": 0,
153+
"new-cap": 0,
154+
"new-parens": 1,
155+
"no-nested-ternary": 0,
156+
"no-array-constructor": 1,
157+
"no-lonely-if": 0,
158+
"no-new-object": 1,
159+
"no-spaced-func": 1,
160+
"semi-spacing": 1,
161+
"no-ternary": 0,
162+
"no-trailing-spaces": 1,
163+
"no-underscore-dangle": 0,
164+
"no-mixed-spaces-and-tabs": 1,
165+
"quotes": [1, "single", "avoid-escape"],
166+
"quote-props": 0,
167+
"semi": 0,
168+
"sort-vars": 0,
169+
"keyword-spacing": 1,
170+
"space-in-brackets": 0,
171+
"space-in-parens": 0,
172+
"space-infix-ops": 1,
173+
"space-unary-ops": [1, { "words": true, "nonwords": false }],
174+
"max-nested-callbacks": 0,
175+
"one-var": 0,
176+
"wrap-regex": 0,
177+
178+
"max-depth": 0,
179+
"max-len": 0,
180+
"max-params": 0,
181+
"max-statements": 0,
182+
"no-bitwise": 1,
183+
"no-plusplus": 0,
184+
185+
"react/display-name": 0,
186+
"react/jsx-boolean-value": 0,
187+
"react/jsx-quotes": [1, "single", "avoid-escape"],
188+
"react/jsx-no-undef": 1,
189+
"react/jsx-sort-props": 0,
190+
"react/jsx-uses-react": 0,
191+
"react/jsx-uses-vars": 1,
192+
"react/no-did-mount-set-state": 1,
193+
"react/no-did-update-set-state": 1,
194+
"react/no-multi-comp": 0,
195+
"react/no-unknown-property": 0,
196+
"react/prop-types": 0,
197+
"react/react-in-jsx-scope": 0,
198+
"react/self-closing-comp": 1,
199+
"react/wrap-multilines": 0
200+
}
201+
}

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- 6.2.0

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# react-native-keyboard-aware-scroll-view
2+
3+
<img src="https://travis-ci.org/APSL/react-native-keyboard-aware-scroll-view.svg?branch=master" />
4+
25
A ScrollView component that handles keyboard appearance and automatically scrolls to focused `TextInput`.
36

47
<p align="center">
58
<img src="https://raw.githubusercontent.com/wiki/APSL/react-native-keyboard-aware-scroll-view/kasv.gif" alt="Scroll demo" width="400">
69
</p>
710

811
## Supported versions
9-
Use `react-native>=0.25.0` for `v0.0.7` & up and `v0.0.6` for older RN versions.
12+
`v0.1.2` requires `RN>=0.27.2`
13+
`v0.0.7` requires `react-native>=0.25.0`
14+
use `v0.0.6` for older RN versions.
1015

1116
## Installation
1217
Installation can be done through ``npm``:
@@ -89,6 +94,7 @@ All the `ScrollView`/`ListView` props will be passed.
8994
|----------|----------|-----------------|
9095
| `viewIsInsideTabBar` | `boolean` | Adds an extra offset that represents the `TabBarIOS` height. |
9196
| `resetScrollToCoords` | `Object: {x: number, y: number}` | Coordinates that will be used to reset the scroll when the keyboard hides. |
97+
| `enableAutoAutomaticScroll` | `boolean` | When focus in TextInput will scroll the position, default is enabled. |
9298
9399
94100
## License

lib/KeyboardAwareMixin.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* @flow */
22

3-
import ReactNative, { TextInput, DeviceEventEmitter, UIManager } from 'react-native'
3+
import { PropTypes } from 'react'
4+
import ReactNative, { TextInput, Keyboard } from 'react-native'
45
import TimerMixin from 'react-timer-mixin'
56

67
const _KAM_DEFAULT_TAB_BAR_HEIGHT = 49
@@ -9,6 +10,17 @@ const _KAM_EXTRA_HEIGHT = 75
910

1011
const KeyboardAwareMixin = {
1112
mixins: [TimerMixin],
13+
propTypes: {
14+
enableAutoAutomaticScroll: PropTypes.bool,
15+
extraHeight: PropTypes.number,
16+
},
17+
18+
getDefaultProps: function () {
19+
return {
20+
enableAutoAutomaticScroll: true,
21+
extraHeight: _KAM_EXTRA_HEIGHT,
22+
}
23+
},
1224

1325
setViewIsInsideTabBar: function (viewIsInsideTabBar: bool) {
1426
this.viewIsInsideTabBar = viewIsInsideTabBar
@@ -35,19 +47,17 @@ const KeyboardAwareMixin = {
3547
keyboardSpace: keyboardSpace,
3648
})
3749
// Automatically scroll to focused TextInput
38-
const currentlyFocusedField = TextInput.State.currentlyFocusedField()
39-
if (!currentlyFocusedField) {
40-
return
41-
}
42-
UIManager.viewIsAncestorOf(
43-
currentlyFocusedField,
44-
this.getScrollHandle().getScrollResponder().getInnerViewNode(),
45-
(isAncestor) => {
46-
if (isAncestor) {
47-
this.scrollToFocusedInputWithNodeHandle(currentlyFocusedField)
48-
}
50+
if (this.props.enableAutoAutomaticScroll) {
51+
const currentlyFocusedField = TextInput.State.currentlyFocusedField()
52+
if (!currentlyFocusedField) {
53+
return
54+
}
55+
try {
56+
this.scrollToFocusedInputWithNodeHandle(currentlyFocusedField)
57+
} catch (e) {
58+
4959
}
50-
)
60+
}
5161
},
5262

5363
resetKeyboardSpace: function () {
@@ -63,8 +73,8 @@ const KeyboardAwareMixin = {
6373

6474
componentDidMount: function () {
6575
// Keyboard events
66-
this.keyboardWillShowEvent = DeviceEventEmitter.addListener('keyboardWillShow', this.updateKeyboardSpace)
67-
this.keyboardWillHideEvent = DeviceEventEmitter.addListener('keyboardWillHide', this.resetKeyboardSpace)
76+
this.keyboardWillShowEvent = Keyboard.addListener('keyboardWillShow', this.updateKeyboardSpace)
77+
this.keyboardWillHideEvent = Keyboard.addListener('keyboardWillHide', this.resetKeyboardSpace)
6878
},
6979

7080
componentWillUnmount: function () {
@@ -80,7 +90,7 @@ const KeyboardAwareMixin = {
8090
/**
8191
* @param extraHeight: takes an extra height in consideration.
8292
*/
83-
scrollToFocusedInput: function (reactNode: Object, extraHeight: number = _KAM_EXTRA_HEIGHT) {
93+
scrollToFocusedInput: function (reactNode: Object, extraHeight: number = this.props.extraHeight) {
8494
const scrollView = this.refs._rnkasv_keyboardView.getScrollResponder()
8595
this.setTimeout(() => {
8696
scrollView.scrollResponderScrollNativeHandleToKeyboard(
@@ -89,7 +99,7 @@ const KeyboardAwareMixin = {
8999
}, _KAM_KEYBOARD_OPENING_TIME)
90100
},
91101

92-
scrollToFocusedInputWithNodeHandle: function (nodeID: number, extraHeight: number = _KAM_EXTRA_HEIGHT) {
102+
scrollToFocusedInputWithNodeHandle: function (nodeID: number, extraHeight: number = this.props.extraHeight) {
93103
const reactNode = ReactNative.findNodeHandle(nodeID)
94104
this.scrollToFocusedInput(reactNode, extraHeight)
95105
},

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "react-native-keyboard-aware-scroll-view",
3-
"version": "0.1.0",
3+
"version": "0.1.2",
44
"description": "A React Native ScrollView component that resizes when the keyboard appears.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"lint": "eslint lib",
8+
"test": "npm run lint"
89
},
910
"repository": {
1011
"type": "git",
@@ -34,5 +35,10 @@
3435
"homepage": "https://github.com/APSL/react-native-keyboard-aware-scroll-view#readme",
3536
"dependencies": {
3637
"react-timer-mixin": "^0.13.3"
38+
},
39+
"devDependencies": {
40+
"babel-eslint": "^6.0.4",
41+
"eslint": "^2.12.0",
42+
"eslint-plugin-react": "^5.1.1"
3743
}
3844
}

0 commit comments

Comments
 (0)