输入聚焦错误时更改边框颜色

马塞尔·楚里什凯夫茨

所以我刚开始反应原生,我得到了';' 预期此功能,我不知道为什么

    getInitialState(){
    return { style: styles.textinput_unfocused }
    }

当输入从灰色聚焦到绿色时,我想更改底部边框的颜色

   <View style={styles.inputStyle}>
     <TextInput style={styles.inputType}
        placeholder='Email'
          onBlur={ () => this.onBlur() }
          onFocus={ () => this.onFocus() }
    style={ [styles.textinput, this.state.style] }

    />
    <TextInput style={styles.inputType}
    placeholder='Password'/>

  </View>

当我稍后在代码中定义这些函数时

      getInitialState(){
          return { style: styles.textinput_unfocused }
          }
      onFocus(){
        this.setState({ style: styles.textinput_focused })
          }

我收到错误,告诉我我错过了;标记任何人都知道为什么或有更好的主意来改变这些输入中的颜色?

泽山·安萨里

您可以使用我的 TextInput 组件,希望您能从我的组件中获得大量信息。

// @flow

import * as React from 'react';
import { View, Text, TextInput } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';

/* FLow Types
============================================================================= */
type State = {
  active: boolean,
};

type KeyboardType = 'default' | 'email-address' | 'numeric' | 'phone-pad';
type KeyboardTypeIOS =
  | 'ascii-capable'
  | 'numbers-and-punctuation'
  | 'url'
  | 'number-pad'
  | 'name-phone-pad'
  | 'decimal-pad'
  | 'twitter'
  | 'web-search';
type KeyboardTypeAndroid = 'visible-password';
type KeyboardTypeOptions = KeyboardType | KeyboardTypeAndroid | KeyboardTypeIOS;

type ReturnKeyType =
  // Cross Platform
  | 'done'
  | 'go'
  | 'next'
  | 'search'
  | 'send'
  // Android-only
  | 'none'
  | 'previous'
  // iOS-only
  | 'default'
  | 'emergency-call'
  | 'google'
  | 'join'
  | 'route'
  | 'yahoo';

type Props = {
  marginVertical?: number,
  labelSize: number,
  labelColor?: string,
  label?: ?string,
  backgroundColor?: string,
  iconName?: ?string,
  reference?: ?Function,
  placeholder?: string,
  placeholderTextColor: string,
  value?: ?string,
  onChange: Function,
  onChangeText: Function,
  onSubmitEditing?: Function,
  secureTextEntry?: boolean,
  multiline?: boolean,
  editable?: boolean,
  returnKeyType?: ReturnKeyType,
  keyboardType?: KeyboardTypeOptions,
  color: string,
};

/* =============================================================================
<InputText />
============================================================================= */
class InputText extends React.PureComponent<Props, State> {
  /**
   * Default Props
   */
  static defaultProps = {
    marginVertical: 5,
    labelColor: '#696969',
    backgroundColor: 'transparent',
    label: null,
    iconName: null,
    reference: null,
    placeholder: '',
    value: '',
    onSubmitEditing: () => {},
    secureTextEntry: false,
    multiline: false,
    editable: true,
    returnKeyType: 'default',
    keyboardType: 'default',
  };

  /**
   * State Here
   */
  state = { active: false };

  /**
   * Start render method
   */
  render() {
    const { active } = this.state;
    const {
      marginVertical,
      labelSize,
      labelColor,
      label,
      backgroundColor,
      iconName,
      reference,
      placeholder,
      placeholderTextColor,
      value,
      onChange,
      onChangeText,
      onSubmitEditing,
      secureTextEntry,
      multiline,
      editable,
      returnKeyType,
      keyboardType,
      color,
    } = this.props;
    return (
      <View style={{ marginVertical }}>
        {label ? (
          <Text style={{ fontSize: labelSize, color: labelColor }}>
            {label}
          </Text>
        ) : null}
        <View
          style={{
            backgroundColor: editable ? backgroundColor : '#DEDEDE',
            borderWidth: 1,
            borderColor: active ? '#3DBA81' : '#CECECE',
            flexDirection: 'row',
            alignItems: 'center',
          }}
        >
          {iconName ? (
            <View
              style={{
                padding: 8,
              }}
            >
              <Icon name={iconName} style={{ fontSize: 20 }} />
            </View>
          ) : null}
          <View
            style={{
              flex: 1,
              justifyContent: 'center',
              paddingHorizontal: 5,
            }}
          >
            <TextInput
              ref={reference}
              placeholder={placeholder}
              placeholderTextColor={editable ? placeholderTextColor : '#575757'}
              value={value}
              onChange={onChange}
              onChangeText={onChangeText}
              onSubmitEditing={onSubmitEditing}
              onFocus={() => this.setState({ active: true })}
              onBlur={() => this.setState({ active: false })}
              autoCorrect={false}
              secureTextEntry={secureTextEntry}
              underlineColorAndroid="transparent"
              multiline={multiline}
              editable={editable}
              returnKeyType={returnKeyType}
              keyboardType={keyboardType}
              style={{ fontSize: 17, color, paddingVertical: 8 }}
            />
          </View>
        </View>
      </View>
    );
  }
}

/* Exports
============================================================================= */
export default InputText;

注意:您可以随心所欲地更改设计。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

angularJS在错误时更改表单输入边框颜色

使用JavaScript输入错误时更改边框颜色

当烧瓶wtforms抛出错误时,如何更改Bootstrap表单输入字段的边框颜色?

聚焦时更改 TextField 的边框颜色

如何更改输入边框颜色

聚焦时如何更改TextField的底部边框颜色?

错误时选择组件材料 ui 中的边框颜色覆盖

聚焦和未聚焦Material UI Input时无法更改边框颜色

buefy输入不更改边框样式的颜色

Javascript代码更改输入边框颜色

何时更改html输入的边框颜色

无输入时更改边框颜色

更改 Angular Mat 输入边框底部颜色

更改 MUI 禁用轮廓输入的边框颜色

单击 -flutter 错误时,轮廓边框更改为单行

在聚焦文本输入字段时如何更改div的背景颜色?

当标签旁边的输入聚焦时,如何更改标签的颜色?

如果输入已经填写,VueJS会更改输入的边框颜色

问题:在Android中更改未聚焦的TextInputLayout的边框颜色或框描边

更改输入[type = text]上灰色“边框”的颜色

ReactJS:更改特定元素ID的输入字段边框颜色

如何获得边框以更改输入焦点中的颜色

如果输入值为空,则更改边框颜色

如何在Xamarin.Forms中更改输入的边框颜色

达到输入 maxLength 后,Ng 样式更改边框颜色

是否可以在验证错误时使输入垫表单字段的整个边框填充为红色

如何在错误时更改PhpStorm主题容器/控制台背景颜色/字体颜色

我想在聚焦时更改边框宽度

聚焦时如何更改边框宽度