-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.native.js
57 lines (50 loc) · 1.37 KB
/
index.native.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* External dependencies
*/
import { TextInput, Platform } from 'react-native';
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
/**
* Internal dependencies
*/
import styles from './style.scss';
export default class PlainText extends Component {
constructor() {
super( ...arguments );
this.isIOS = Platform.OS === 'ios';
}
componentDidMount() {
// if isSelected is true, we should request the focus on this TextInput
if ( ( this._input.isFocused() === false ) && ( this._input.props.isSelected === true ) ) {
this.focus();
}
}
componentDidUpdate( prevProps ) {
if ( ! this.props.isSelected && prevProps.isSelected && this.isIOS ) {
this._input.blur();
}
}
focus() {
this._input.focus();
}
render() {
return (
<TextInput
{ ...this.props }
ref={ ( x ) => this._input = x }
className={ [ styles[ 'block-editor-plain-text' ], this.props.className ] }
onChange={ ( event ) => {
this.props.onChange( event.nativeEvent.text );
} }
onFocus={ this.props.onFocus } // always assign onFocus as a props
onBlur={ this.props.onBlur } // always assign onBlur as a props
fontFamily={ this.props.fontFamily || ( styles[ 'block-editor-plain-text' ].fontFamily ) }
fontSize={ this.props.fontSize }
fontWeight={ this.props.fontWeight }
fontStyle={ this.props.fontStyle }
/>
);
}
}