Skip to content

Commit ce6e338

Browse files
bugs181alvaromb
authored andcommitted
Component driven update method (APSL#251)
Adds an `update` method to allow components the ability to re-scroll to the selected field based on some user-defined event. Fixes issues that most users are having with auto-growing, resizing, updated or multiline `TextInput` fields. Examples and Videos description closes APSL#250
1 parent 9a8cd7a commit ce6e338

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/KeyboardAwareHOC.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type KeyboardAwareHOCProps = {
3030
extraScrollHeight?: number,
3131
keyboardOpeningTime?: number,
3232
onScroll?: Function,
33+
update?: Function,
3334
contentContainerStyle?: any,
3435
enableOnAndroid?: boolean,
3536
innerRef?: Function
@@ -96,6 +97,7 @@ function listenToKeyboardEvents(ScrollableComponent: React$Component) {
9697
extraScrollHeight: PropTypes.number,
9798
keyboardOpeningTime: PropTypes.number,
9899
onScroll: PropTypes.func,
100+
update: PropTypes.func,
99101
contentContainerStyle: PropTypes.any,
100102
enableOnAndroid: PropTypes.bool,
101103
innerRef: PropTypes.func
@@ -382,6 +384,19 @@ function listenToKeyboardEvents(ScrollableComponent: React$Component) {
382384
}
383385
}
384386

387+
update = () => {
388+
const currentlyFocusedField = TextInput.State.currentlyFocusedField()
389+
const responder = this.getScrollResponder()
390+
391+
if (!currentlyFocusedField || !responder) {
392+
return
393+
}
394+
395+
this._scrollToFocusedInputWithNodeHandle(
396+
currentlyFocusedField
397+
)
398+
}
399+
385400
render() {
386401
const { enableOnAndroid, contentContainerStyle, onScroll } = this.props
387402
let newContentContainerStyle
@@ -413,6 +428,7 @@ function listenToKeyboardEvents(ScrollableComponent: React$Component) {
413428
scrollIntoView={this.scrollIntoView}
414429
resetKeyboardSpace={this._resetKeyboardSpace}
415430
handleOnScroll={this._handleOnScroll}
431+
update={this.update}
416432
onScroll={Animated.forkEvent(onScroll,this._handleOnScroll)}
417433
/>
418434
)

0 commit comments

Comments
 (0)