Skip to content

Commit 4d065d7

Browse files
Swordsman-Inactionalvaromb
authored andcommitted
Advanced 103 (#109)
* Feat: add scrollToEnd to mixin * Refactor move getScrollResponder to mixin * Fix type * Update doc
1 parent 48a9628 commit 4d065d7

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ All the `ScrollView`/`ListView` props will be passed.
104104
| `extraScrollHeight` | `number` | Adds an extra offset to the keyboard. Useful if you want to stick elements above the keyboard. |
105105
| `enableResetScrollToCoords` | `boolean` | Lets the user enable or disable automatic resetScrollToCoords. |
106106
107+
### Methods
108+
109+
| **Method** | **Parameter** | **Description** |
110+
|------------|---------------|-----------------|
111+
| `getScrollResponder` | `void` | Get `ScrollResponder` |
112+
| `scrollToPosition` | `x: number, y: number, animated: bool = true` | Scroll to specific position with or without animation. |
113+
| `scrollToEnd` | `animated?: bool = true` | Scroll to end with or without animation. |
114+
107115
## License
108116
109117
MIT.

lib/KeyboardAwareListView.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ const KeyboardAwareListView = React.createClass({
1919
this.setResetScrollToCoords(this.props.resetScrollToCoords)
2020
},
2121

22-
getScrollResponder() {
23-
return this.refs._rnkasv_keyboardView.getScrollResponder()
24-
},
25-
2622
render: function () {
2723
return (
2824
<ListView

lib/KeyboardAwareMixin.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,24 @@ const KeyboardAwareMixin = {
112112
this.keyboardWillHideEvent && this.keyboardWillHideEvent.remove()
113113
},
114114

115-
scrollToPosition: function (x: number, y: number, animated: bool = false) {
116-
const scrollView = this.refs._rnkasv_keyboardView.getScrollResponder()
117-
scrollView.scrollResponderScrollTo({x: x, y: y, animated: animated})
115+
getScrollResponder() {
116+
return this.refs._rnkasv_keyboardView.getScrollResponder()
117+
},
118+
119+
scrollToPosition: function (x: number, y: number, animated: bool = true) {
120+
this.getScrollResponder().scrollResponderScrollTo({x: x, y: y, animated: animated})
121+
},
122+
123+
scrollToEnd: function (animated?: bool = true) {
124+
this.getScrollResponder().scrollResponderScrollToEnd({animated: animated})
118125
},
119126

120127
/**
121128
* @param extraHeight: takes an extra height in consideration.
122129
*/
123130
scrollToFocusedInput: function (reactNode: Object, extraHeight: number = this.props.extraHeight) {
124-
const scrollView = this.refs._rnkasv_keyboardView.getScrollResponder()
125131
this.setTimeout(() => {
126-
scrollView.scrollResponderScrollNativeHandleToKeyboard(
132+
this.getScrollResponder().scrollResponderScrollNativeHandleToKeyboard(
127133
reactNode, extraHeight, true
128134
)
129135
}, _KAM_KEYBOARD_OPENING_TIME)

lib/KeyboardAwareScrollView.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ const KeyboardAwareScrollView = React.createClass({
2020
this.setResetScrollToCoords(this.props.resetScrollToCoords)
2121
},
2222

23-
getScrollResponder() {
24-
return this.refs._rnkasv_keyboardView.getScrollResponder()
25-
},
26-
2723
render: function () {
2824
return (
2925
<ScrollView

0 commit comments

Comments
 (0)