Skip to content

Commit

Permalink
Mobile - Aztec - Trigger notifyInputChange on both blur and focus whe…
Browse files Browse the repository at this point in the history
…n they're called directly as well as checking there are listeners set before notifying
  • Loading branch information
Gerardo committed May 4, 2022
1 parent 3929ae8 commit edd61d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/react-native-aztec/src/AztecInputState.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,18 @@ export const getCurrentFocusedElement = () => {
export const notifyInputChange = () => {
const focusedInput = TextInputState.currentlyFocusedInput();
const hasAnyFocusedInput = focusedInput !== null;
const hasListeners = focusChangeListeners.length > 0;

if ( hasAnyFocusedInput ) {
if ( ! currentFocusedElement ) {
notifyListeners( { isFocused: true } );
if ( hasListeners ) {
if ( hasAnyFocusedInput ) {
if ( ! currentFocusedElement ) {
notifyListeners( { isFocused: true } );
}
currentFocusedElement = focusedInput;
} else if ( currentFocusedElement ) {
notifyListeners( { isFocused: false } );
currentFocusedElement = null;
}
currentFocusedElement = focusedInput;
} else if ( currentFocusedElement ) {
notifyListeners( { isFocused: false } );
currentFocusedElement = null;
}
};

Expand Down
3 changes: 3 additions & 0 deletions packages/react-native-aztec/src/AztecView.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,13 @@ class AztecView extends Component {

blur() {
AztecInputState.blur( this.aztecViewRef.current );
// Unmounting the component needs to update the current focused element
AztecInputState.notifyInputChange();
}

focus() {
AztecInputState.focus( this.aztecViewRef.current );
AztecInputState.notifyInputChange();
}

isFocused() {
Expand Down

0 comments on commit edd61d8

Please sign in to comment.