<commit_before>import * as React from 'react';
import AbstractComponent from '../../AbstractComponent';
import { View, Animated, StyleSheet, StyleProp, ViewStyle } from 'react-native';
import Input from '../../Input';
import Picker from '../../Picker';

import { Props } from './Props';
import { getStyles } from './styles';


/**
 * @author 田尘殇Sean(<EMAIL>) create at 2017/12/20
 */
export default class TextField extends AbstractComponent<Props> {

  static defaultProps = {
    underlineShow: true
  };

  state;

  // refs
  input;

  constructor(props) {
    super(props);
    this.state = {};
    if (props.underlineShow) {
      this.state.focus = props.autoFocus;
      this.state.height = new Animated.Value(this.getHeightStartValue());
    }
  }

  focus() {
    this.input && this.input.focus();
  }

  getHeightStartValue(): any {
    const style: StyleProp<ViewStyle> = [getStyles().underline, this.props.underlineStyle];
    return StyleSheet.flatten(style).height || 0.5;
  }

  getHeightEndValue(): any {
    const style: StyleProp<ViewStyle> = [getStyles().underlineFocus, this.props.underlineFocusStyle];
    return StyleSheet.flatten(style).height || 1;
  }

  handleFocus() {
    const {onFocus, underlineShow} = this.props;
    if (underlineShow) {
      this.setState({focus: true}, () => Animated.timing(this.state.height, {
        toValue: this.getHeightEndValue()
      }).start());
    }
    onFocus && onFocus();
  }

  handleBlur() {
    const {onBlur, underlineShow} = this.props;
    if (underlineShow) {
      this.setState({focus: false}, () => Animated.timing(this.state.height, {
        toValue: this.getHeightStartValue()
      }).start());
    }
    onBlur && onBlur();
  }

  renderFloatingLabel() {
    const {
      floatingLabelText,
      floatingLabelStyle,
      floatingLabelFocusStyle
    } = this.props;
    const style = [];
    style.push(getStyles().floatingLabel);
    style.push(floatingLabelStyle);

    if (this.state.focus) {
      style.push(getStyles().floatingLabelFocus);
      style.push(floatingLabelFocusStyle);
    }

    return (
      <Animated.Text style={style}>
        {floatingLabelText}
      </Animated.Text>
    )
  }

  renderUnderline() {
    const {underlineShow, underlineStyle} = this.props;
    if (!underlineShow) {
      return null;
    }
    const style = [];
    const {
      editable,
      underlineDisabledStyle,
      underlineFocusStyle
    } = this.props;

    style.push(getStyles().underline);
    style.push(underlineStyle);
    if (editable && !editable) {
      style.push(getStyles().underlineDisabled);
      style.push(underlineDisabledStyle);
    }

    if (this.state.focus) {
      style.push(getStyles().underlineFocus);
      style.push(underlineFocusStyle);
    }
    return (
      <Animated.View style={[style, {height: this.state.height}]}/>
    )
  }

  render() {

    const {
      containerStyle,
      type,
      children,
      ...props
    } = this.props;

    let comp: any = (
      <Input {...props}
             children={children}
             ref={input => this.input = input}
             onBlur={this.handleBlur}
             onFocus={this.handleFocus}
             style={getStyles().input}
      />
    );
    if (type === 'select') {
      comp = (
        <Picker {...props}
                style={getStyles().input}
        >
          {children}
        </Picker>
      );
    } else if (children) {
      comp = children;
    }

    return (
      <View style={[getStyles().container, containerStyle]}>
        {this.renderFloatingLabel()}
        {comp}
        {this.renderUnderline()}
      </View>
    );
  }

}<commit_msg>input 初始化<commit_after>import * as React from 'react';
import AbstractComponent from '../../AbstractComponent';
import { View, Animated, StyleSheet, StyleProp, ViewStyle } from 'react-native';
import Input from '../../Input';
import Picker from '../../Picker';

import { Props } from './Props';
import { getStyles } from './styles';


/**
 * @author 田尘殇Sean(<EMAIL>) create at 2017/12/20
 */
export default class TextField extends AbstractComponent<Props> {

  static defaultProps = {
    underlineShow: true
  };

  state;

  // refs
  input;

  constructor(props) {
    super(props);
    this.state = {};
    if (props.underlineShow) {
      this.state.focus = props.autoFocus;
      this.state.height = new Animated.Value(this.getHeightStartValue());
    }
  }

  focus() {
    this.input && this.input.focus();
  }

  getHeightStartValue(): any {
    const style: StyleProp<ViewStyle> = [getStyles().underline, this.props.underlineStyle];
    return StyleSheet.flatten(style).height || 0.5;
  }

  getHeightEndValue(): any {
    const style: StyleProp<ViewStyle> = [getStyles().underlineFocus, this.props.underlineFocusStyle];
    return StyleSheet.flatten(style).height || 1;
  }

  handleFocus() {
    const {onFocus, underlineShow} = this.props;
    if (underlineShow) {
      this.setState({focus: true}, () => Animated.timing(this.state.height, {
        toValue: this.getHeightEndValue()
      }).start());
    }
    onFocus && onFocus();
  }

  handleBlur() {
    const {onBlur, underlineShow} = this.props;
    if (underlineShow) {
      this.setState({focus: false}, () => Animated.timing(this.state.height, {
        toValue: this.getHeightStartValue()
      }).start());
    }
    onBlur && onBlur();
  }

  renderFloatingLabel() {
    const {
      floatingLabelText,
      floatingLabelStyle,
      floatingLabelFocusStyle
    } = this.props;
    const style = [];
    style.push(getStyles().floatingLabel);
    style.push(floatingLabelStyle);

    if (this.state.focus) {
      style.push(getStyles().floatingLabelFocus);
      style.push(floatingLabelFocusStyle);
    }

    return (
      <Animated.Text style={style}>
        {floatingLabelText}
      </Animated.Text>
    )
  }

  renderUnderline() {
    const {underlineShow, underlineStyle} = this.props;
    if (!underlineShow) {
      return null;
    }
    const style = [];
    const {
      editable,
      underlineDisabledStyle,
      underlineFocusStyle
    } = this.props;

    style.push(getStyles().underline);
    style.push(underlineStyle);
    if (editable && !editable) {
      style.push(getStyles().underlineDisabled);
      style.push(underlineDisabledStyle);
    }

    if (this.state.focus) {
      style.push(getStyles().underlineFocus);
      style.push(underlineFocusStyle);
    }
    return (
      <Animated.View style={[style, {height: this.state.height}]}/>
    )
  }

  render() {

    const {
      containerStyle,
      type,
      children,
      ...props
    } = this.props;

    this.input = (
      <Input {...props}
             children={children}
             onBlur={this.handleBlur}
             onFocus={this.handleFocus}
             style={getStyles().input}
      />
    );
    let comp = this.input;
    if (type === 'select') {
      comp = (
        <Picker {...props}
                style={getStyles().input}
        >
          {children}
        </Picker>
      );
    } else if (children) {
      comp = children;
    }

    return (
      <View style={[getStyles().container, containerStyle]}>
        {this.renderFloatingLabel()}
        {comp}
        {this.renderUnderline()}
      </View>
    );
  }

}
{'fraction_non_alphanumeric': 0.14648196406528596, 'fraction_numerical': 0.003017418735427239, 'mean_word_length': 2.4641330166270783, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6864444', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2249, 'n_words': 411}