Skip to content

Commit

Permalink
Mobile - AztecView - Trigger notifyInputChange on focus/blur (#40788)
Browse files Browse the repository at this point in the history
* Mobile - BlockDraggable - Set isEditingText to false and update it with the initialization of the AztecView listener

* Mobile - AztecView - Move notifyInputChange to the focus/blur functions within AztecInputState, to fix an issue where these are called directly.
  • Loading branch information
Gerardo Pacheco authored May 6, 2022
1 parent 3714b15 commit 0c34e55
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,7 @@ const BlockDraggableWrapper = ( { children } ) => {
*/
const BlockDraggable = ( { clientId, children, enabled = true } ) => {
const wasBeingDragged = useRef( false );
const [ isEditingText, setIsEditingText ] = useState(
RCTAztecView.InputState.isFocused()
);
const [ isEditingText, setIsEditingText ] = useState( false );

const draggingAnimation = {
opacity: useSharedValue( 1 ),
Expand Down Expand Up @@ -327,6 +325,11 @@ const BlockDraggable = ( { clientId, children, enabled = true } ) => {
}, [] );

useEffect( () => {
const isAnyAztecInputFocused = RCTAztecView.InputState.isFocused();
if ( isAnyAztecInputFocused ) {
setIsEditingText( isAnyAztecInputFocused );
}

RCTAztecView.InputState.addFocusChangeListener( onFocusChangeAztec );
return () => {
RCTAztecView.InputState.removeFocusChangeListener(
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-aztec/src/AztecInputState.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const notifyInputChange = () => {
*/
export const focus = ( element ) => {
TextInputState.focusTextInput( element );
notifyInputChange();
};

/**
Expand All @@ -99,6 +100,7 @@ export const focus = ( element ) => {
*/
export const blur = ( element ) => {
TextInputState.blurTextInput( element );
notifyInputChange();
};

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

_onFocus( event ) {
AztecInputState.notifyInputChange();

if ( ! this.props.onFocus ) {
return;
}
Expand All @@ -136,7 +134,6 @@ class AztecView extends Component {
this.selectionEndCaretY = null;

AztecInputState.blur( this.aztecViewRef.current );
AztecInputState.notifyInputChange();

if ( ! this.props.onBlur ) {
return;
Expand Down

0 comments on commit 0c34e55

Please sign in to comment.