From 5d16771c60f08241d1ec95e9840a22d66985ebad Mon Sep 17 00:00:00 2001 From: matiassalles99 Date: Tue, 5 Apr 2022 15:45:08 -0300 Subject: [PATCH] add flash scroll indicators --- index.d.ts | 15 ++++++++------- lib/KeyboardAwareHOC.js | 16 +++++++++++++--- lib/KeyboardAwareInterface.js | 1 + 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/index.d.ts b/index.d.ts index bf03b269..5cbb3bfe 100644 --- a/index.d.ts +++ b/index.d.ts @@ -145,13 +145,13 @@ interface KeyboardAwareProps { interface KeyboardAwareScrollViewProps extends KeyboardAwareProps, - ScrollViewProps {} + ScrollViewProps { } interface KeyboardAwareFlatListProps extends KeyboardAwareProps, - FlatListProps {} + FlatListProps { } interface KeyboardAwareSectionListProps extends KeyboardAwareProps, - SectionListProps {} + SectionListProps { } interface KeyboardAwareState { keyboardSpace: number @@ -167,18 +167,19 @@ declare class ScrollableComponent extends React.Component { extraHeight?: number, keyboardOpeningTime?: number ) => void + flashScrollIndicators: () => void } -export class KeyboardAwareMixin {} +export class KeyboardAwareMixin { } export class KeyboardAwareScrollView extends ScrollableComponent< KeyboardAwareScrollViewProps, KeyboardAwareState -> {} +> { } export class KeyboardAwareFlatList extends ScrollableComponent< KeyboardAwareFlatListProps, KeyboardAwareState -> {} +> { } export class KeyboardAwareSectionList extends ScrollableComponent< KeyboardAwareSectionListProps, KeyboardAwareState -> {} +> { } diff --git a/lib/KeyboardAwareHOC.js b/lib/KeyboardAwareHOC.js index 03f46af5..05fa46f2 100644 --- a/lib/KeyboardAwareHOC.js +++ b/lib/KeyboardAwareHOC.js @@ -303,6 +303,16 @@ function KeyboardAwareHOC( this.scrollToPosition(0, this.position.y + extraHeight, true) } + flashScrollIndicators = () => { + const responder = this.getScrollResponder() + if (!responder) { + return + } + if (responder.flashScrollIndicators) { + responder.flashScrollIndicators() + } + } + /** * @param keyboardOpeningTime: takes a different keyboardOpeningTime in consideration. * @param extraHeight: takes an extra height in consideration. @@ -389,7 +399,7 @@ function KeyboardAwareHOC( keyboardSpace -= _KAM_DEFAULT_TAB_BAR_HEIGHT } this.setState({ keyboardSpace }) - const currentlyFocusedField = TextInput.State.currentlyFocusedInput ? findNodeHandle(TextInput.State.currentlyFocusedInput()) : TextInput.State.currentlyFocusedField() + const currentlyFocusedField = TextInput.State.currentlyFocusedInput ? findNodeHandle(TextInput.State.currentlyFocusedInput()) : TextInput.State.currentlyFocusedField() const responder = this.getScrollResponder() if (!currentlyFocusedField || !responder) { return @@ -434,7 +444,7 @@ function KeyboardAwareHOC( ) { this.scrollForExtraHeightOnAndroid( totalExtraHeight - - (keyboardPosition - textInputBottomPosition) + (keyboardPosition - textInputBottomPosition) ) } } @@ -512,7 +522,7 @@ function KeyboardAwareHOC( } update = () => { - const currentlyFocusedField = TextInput.State.currentlyFocusedInput ? findNodeHandle(TextInput.State.currentlyFocusedInput()) : TextInput.State.currentlyFocusedField() + const currentlyFocusedField = TextInput.State.currentlyFocusedInput ? findNodeHandle(TextInput.State.currentlyFocusedInput()) : TextInput.State.currentlyFocusedField() const responder = this.getScrollResponder() if (!currentlyFocusedField || !responder) { diff --git a/lib/KeyboardAwareInterface.js b/lib/KeyboardAwareInterface.js index 20fbcb49..4c23a877 100644 --- a/lib/KeyboardAwareInterface.js +++ b/lib/KeyboardAwareInterface.js @@ -10,4 +10,5 @@ export interface KeyboardAwareInterface { extraHeight: number, keyboardOpeningTime: number ) => void + flashScrollIndicators: () => void }