Skip to content

Commit a2689b1

Browse files
Swordsman-Inactionalvaromb
authored andcommitted
Feat(Restore Position): Change default reset action (APSL#52)
* Feat(Restore Position): Change default reset action * Feat(Restore Position): add the same feature for scrollview * Fix(remove unnecessary function)
1 parent 98d2382 commit a2689b1

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/KeyboardAwareListView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const KeyboardAwareListView = React.createClass({
3232
contentInset={{bottom: this.state.keyboardSpace}}
3333
showsVerticalScrollIndicator={true}
3434
{...this.props}
35+
onScroll={e => {
36+
this.handleOnScroll(e)
37+
this.props.onScroll && this.props.onScroll(e)
38+
}}
3539
/>
3640
)
3741
},

lib/KeyboardAwareMixin.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ const KeyboardAwareMixin = {
6262
}
6363
)
6464
}
65+
66+
if (!this.resetCoords) {
67+
this.defaultResetScrollToCoords = this.position
68+
}
6569
},
6670

6771
resetKeyboardSpace: function () {
@@ -72,6 +76,8 @@ const KeyboardAwareMixin = {
7276
// Reset scroll position after keyboard dismissal
7377
if (this.resetCoords) {
7478
this.scrollToPosition(this.resetCoords.x, this.resetCoords.y, true)
79+
} else {
80+
this.scrollToPosition(this.defaultResetScrollToCoords.x, this.defaultResetScrollToCoords.y, true)
7581
}
7682
},
7783

@@ -107,6 +113,14 @@ const KeyboardAwareMixin = {
107113
const reactNode = ReactNative.findNodeHandle(nodeID)
108114
this.scrollToFocusedInput(reactNode, extraHeight)
109115
},
116+
117+
position: {x: 0, y: 0},
118+
119+
defaultResetScrollToCoords: {x: 0, y: 0},
120+
121+
handleOnScroll: function (e) {
122+
this.position = e.nativeEvent.contentOffset
123+
},
110124
}
111125

112126
export default KeyboardAwareMixin

lib/KeyboardAwareScrollView.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ const KeyboardAwareScrollView = React.createClass({
3131
keyboardDismissMode='interactive'
3232
contentInset={{bottom: this.state.keyboardSpace}}
3333
showsVerticalScrollIndicator={true}
34-
{...this.props}>
34+
{...this.props}
35+
onScroll={e => {
36+
this.handleOnScroll(e)
37+
this.props.onScroll && this.props.onScroll(e)
38+
}}
39+
>
3540
{this.props.children}
3641
</ScrollView>
3742
)

0 commit comments

Comments
 (0)