mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-08-15 18:45:06 +00:00
@@ -90,7 +90,10 @@ export default class App extends React.Component {
|
|||||||
/>
|
/>
|
||||||
<TextInput secureTextEntry />
|
<TextInput secureTextEntry />
|
||||||
<TextInput defaultValue='read only' editable={false} />
|
<TextInput defaultValue='read only' editable={false} />
|
||||||
<TextInput style={{ flex:1, height: 60, padding: 20 }} keyboardType='email-address' placeholder='you@domain.com' placeholderTextColor='red' />
|
<TextInput
|
||||||
|
style={{ flex:1, height: 60, padding: 20, fontSize: 20, textAlign: 'center' }}
|
||||||
|
keyboardType='email-address' placeholder='you@domain.com' placeholderTextColor='red'
|
||||||
|
/>
|
||||||
<TextInput keyboardType='numeric' />
|
<TextInput keyboardType='numeric' />
|
||||||
<TextInput keyboardType='phone-pad' />
|
<TextInput keyboardType='phone-pad' />
|
||||||
<TextInput defaultValue='https://delete-me' keyboardType='url' placeholder='https://www.some-website.com' selectTextOnFocus />
|
<TextInput defaultValue='https://delete-me' keyboardType='url' placeholder='https://www.some-website.com' selectTextOnFocus />
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import createNativeComponent from '../../modules/createNativeComponent'
|
import createNativeComponent from '../../modules/createNativeComponent'
|
||||||
import NativeMethodsDecorator from '../../modules/NativeMethodsDecorator'
|
import NativeMethodsDecorator from '../../modules/NativeMethodsDecorator'
|
||||||
|
import omit from 'lodash/omit'
|
||||||
|
import pick from 'lodash/pick'
|
||||||
import React, { Component, PropTypes } from 'react'
|
import React, { Component, PropTypes } from 'react'
|
||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom'
|
||||||
import StyleSheet from '../../apis/StyleSheet'
|
import StyleSheet from '../../apis/StyleSheet'
|
||||||
@@ -7,6 +9,9 @@ import Text from '../Text'
|
|||||||
import TextareaAutosize from 'react-textarea-autosize'
|
import TextareaAutosize from 'react-textarea-autosize'
|
||||||
import TextInputState from './TextInputState'
|
import TextInputState from './TextInputState'
|
||||||
import View from '../View'
|
import View from '../View'
|
||||||
|
import ViewStylePropTypes from '../View/ViewStylePropTypes'
|
||||||
|
|
||||||
|
const viewStyleProps = Object.keys(ViewStylePropTypes)
|
||||||
|
|
||||||
@NativeMethodsDecorator
|
@NativeMethodsDecorator
|
||||||
class TextInput extends Component {
|
class TextInput extends Component {
|
||||||
@@ -114,6 +119,12 @@ class TextInput extends Component {
|
|||||||
type = 'password'
|
type = 'password'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In order to support 'Text' styles on 'TextInput', we split the 'Text'
|
||||||
|
// and 'View' styles and apply them to the 'Text' and 'View' components
|
||||||
|
// used in the implementation
|
||||||
|
const rootStyles = pick(style, viewStyleProps)
|
||||||
|
const textStyles = omit(style, viewStyleProps)
|
||||||
|
|
||||||
const propsCommon = {
|
const propsCommon = {
|
||||||
autoComplete: autoComplete && 'on',
|
autoComplete: autoComplete && 'on',
|
||||||
autoFocus,
|
autoFocus,
|
||||||
@@ -124,7 +135,7 @@ class TextInput extends Component {
|
|||||||
onFocus: this._handleFocus,
|
onFocus: this._handleFocus,
|
||||||
onSelect: onSelectionChange && this._handleSelectionChange,
|
onSelect: onSelectionChange && this._handleSelectionChange,
|
||||||
readOnly: !editable,
|
readOnly: !editable,
|
||||||
style: { ...styles.input, outline: style.outline },
|
style: { ...styles.input, ...textStyles, outline: style.outline },
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,26 +154,29 @@ class TextInput extends Component {
|
|||||||
|
|
||||||
const props = multiline ? propsMultiline : propsSingleline
|
const props = multiline ? propsMultiline : propsSingleline
|
||||||
|
|
||||||
|
const optionalPlaceholder = placeholder && this.state.showPlaceholder && (
|
||||||
|
<View pointerEvents='none' style={styles.placeholder}>
|
||||||
|
<Text
|
||||||
|
children={placeholder}
|
||||||
|
style={[
|
||||||
|
styles.placeholderText,
|
||||||
|
textStyles,
|
||||||
|
placeholderTextColor && { color: placeholderTextColor }
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
accessibilityLabel={accessibilityLabel}
|
accessibilityLabel={accessibilityLabel}
|
||||||
onClick={this._handleClick}
|
onClick={this._handleClick}
|
||||||
style={[ styles.initial, style ]}
|
style={[ styles.initial, rootStyles ]}
|
||||||
testID={testID}
|
testID={testID}
|
||||||
>
|
>
|
||||||
<View style={styles.wrapper}>
|
<View style={styles.wrapper}>
|
||||||
{createNativeComponent({ ...props, ref: 'input' })}
|
{createNativeComponent({ ...props, ref: 'input' })}
|
||||||
{placeholder && this.state.showPlaceholder && (
|
{optionalPlaceholder}
|
||||||
<View pointerEvents='none' style={styles.placeholder}>
|
|
||||||
<Text
|
|
||||||
children={placeholder}
|
|
||||||
style={[
|
|
||||||
styles.placeholderText,
|
|
||||||
placeholderTextColor && { color: placeholderTextColor }
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user