Skip to content

Commit

Permalink
Use old implementation of TextInputState in AztecView
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhun committed Oct 1, 2020
1 parent f1c73a1 commit f0ea684
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions packages/react-native-aztec/src/AztecView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import ReactNative, {
TouchableWithoutFeedback,
Platform,
} from 'react-native';
import TextInputState from 'react-native/Libraries/Components/TextInput/TextInputState';
/**
* WordPress dependencies
*/
import { ENTER, BACKSPACE } from '@wordpress/keycodes';

const AztecManager = UIManager.getViewManagerConfig( 'RCTAztecView' );

let currentlyFocusedID = null;

class AztecView extends React.Component {
constructor() {
super( ...arguments );
Expand Down Expand Up @@ -125,7 +126,7 @@ class AztecView extends React.Component {

_onBlur( event ) {
this.selectionEndCaretY = null;
TextInputState.blurTextInput( ReactNative.findNodeHandle( this ) );
this.blur();

if ( ! this.props.onBlur ) {
return;
Expand Down Expand Up @@ -177,17 +178,43 @@ class AztecView extends React.Component {
}

blur() {
TextInputState.blurTextInput( ReactNative.findNodeHandle( this ) );
const textFieldID = ReactNative.findNodeHandle( this );
if ( currentlyFocusedID === textFieldID && textFieldID !== null ) {
currentlyFocusedID = null;
if ( Platform.OS === 'ios' ) {
UIManager.blur( textFieldID );
} else if ( Platform.OS === 'android' ) {
UIManager.dispatchViewManagerCommand(
textFieldID,
UIManager.getViewManagerConfig( 'AndroidTextInput' )
.Commands.blurTextInput,
null
);
}
}
}

focus() {
TextInputState.focusTextInput( ReactNative.findNodeHandle( this ) );
const textFieldID = ReactNative.findNodeHandle( this );
if ( currentlyFocusedID !== textFieldID && textFieldID !== null ) {
currentlyFocusedID = textFieldID;
if ( Platform.OS === 'ios' ) {
UIManager.focus( textFieldID );
} else if ( Platform.OS === 'android' ) {
UIManager.dispatchViewManagerCommand(
textFieldID,
UIManager.getViewManagerConfig( 'AndroidTextInput' )
.Commands.focusTextInput,
null
);
}
}
}

isFocused() {
const focusedField = TextInputState.currentlyFocusedField();
return (
focusedField && focusedField === ReactNative.findNodeHandle( this )
currentlyFocusedID &&
currentlyFocusedID === ReactNative.findNodeHandle( this )
);
}

Expand Down

0 comments on commit f0ea684

Please sign in to comment.