<commit_before>import React, { PropTypes } from 'react';
import { ActivityIndicator, StatusBar, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import Component from './AbstractComponent';
import { View as AnimatableView } from 'react-native-animatable';
import createRootView from './createRootView';

const styles = StyleSheet.create({
  container: {
    position: 'absolute',
    left: 0,
    right: 0,
    top: 0,
    bottom: 0
  },
  loadingStyle: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'rgba(0,0,0,.4)'
  },
  content: {
    borderRadius: 10,
    padding: 20,
    alignItems: 'center',
    backgroundColor: 'rgba(0,0,0,0.7)'
  },
  text: {
    marginTop: 5,
    color: '#FFF'
  }
});

/**
 * @author 田尘殇Sean(<EMAIL>)
 * @date 16/5/24
 */
class Dialog extends Component {

  static propTypes = {
    hideAnimation: PropTypes.object,
    loadChildren: PropTypes.node,
    loadProps: PropTypes.object,
    loading: PropTypes.bool,
    showAnimation: PropTypes.object,
    statusBarAutoHidden: PropTypes.bool,
    style: View.propTypes.style,
    visible: PropTypes.bool,
    onPress: PropTypes.func
  };

  static defaultProps = {
    activeOpacity: 1,
    visible: false,
    statusBarAutoHidden: true
  };

  state = {
    animating: false,
    visible: false
  };

  mounted = true;

  shounldComponentUpdate() {
    return !this.state.animating;
  }

  componentWillUnmount() {
    if (this.statusBarHidden) {
      StatusBar.setHidden(false);
    }
    this.mounted = false;
  }

  handlePress() {
    let {onPress} = this.props;
    onPress && onPress();
  }

  handleAnimationBegin() {
    this.setState({animating: true});
  }

  handleAnimationEnd() {
    if (!this.mounted) {
      return;
    }
    let {
      visible,
      statusBarAutoHidden
    } = this.props;

    if (visible) {
      if (statusBarAutoHidden) {
        this.statusBarHidden = true;
        StatusBar.setHidden(true);
      }
    } else {
      if (this.statusBarHidden) {
        this.statusBarHidden = false;
        StatusBar.setHidden(false);
      }
    }

    this.setState({
      visible,
      animating: false
    });

  }

  renderLoading(loadProps, loadChildren) {
    return (
      <View style={styles.content}>
        <ActivityIndicator {...loadProps}/>
        {typeof loadChildren === 'string' ? (
          <Text style={styles.text}>
            {loadChildren}
          </Text>
        ) : loadChildren}
      </View>
    );
  }

  render() {

    let {
      children,
      activeOpacity,
      visible,
      style,
      showAnimation,
      hideAnimation,
      loading,
      loadProps,
      loadChildren
    } = this.props;

    if (!visible && !this.state.visible) {
      return <View />;
    }

    let animation = visible ? showAnimation : hideAnimation;

    let tmp = loading ? styles.loadingStyle : null;

    return (
      <AnimatableView {...animation}
                      onAnimationBegin={this.handleAnimationBegin}
                      onAnimationEnd={this.handleAnimationEnd}
                      style={[styles.container, tmp, style]}
      >
        <TouchableOpacity
          activeOpacity={activeOpacity}
          onPress={this.handlePress}
          style={styles.container}
        />
        {loading ? this.renderLoading(loadProps, loadChildren) : children}
      </AnimatableView>
    );
  }
}

// noinspection Eslint
export default createRootView(Dialog);<commit_msg>使用Modal实现<commit_after>import React, { PropTypes } from 'react';
import Component from './AbstractComponent';
import { ActivityIndicator, Modal, StyleSheet, Text, View } from 'react-native';
import createRootView from './createRootView';
import { getWindowSize } from './styles';

const styles = StyleSheet.create({
  loadingContainer: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'rgba(0,0,0,.4)'
  },
  content: {
    borderRadius: 10,
    padding: 20,
    alignItems: 'center',
    backgroundColor: 'rgba(0,0,0,0.7)'
  },
  text: {
    marginTop: 5,
    color: '#FFF'
  }
});

/**
 * @author 田尘殇Sean(<EMAIL>)
 * @date 16/5/24
 */
class Dialog extends Component {

  static propTypes = {
    ...Modal.propTypes,
    isLoadingDialog: PropTypes.bool,
    loadingProps: PropTypes.object,
    style: View.propTypes.style
  };

  static defaultProps = {
    animationType: 'fade',
    onRequestClose() {
      console.log('Dialog close');
    },
    isLoadingDialog: false,
    transparent: true,
    visible: false
  };

  renderLoading({children, loadingProps}) {
    let child;
    if (typeof children === 'string') {
      child = <Text style={styles.text}>{children}</Text>;
    } else if (Array.isArray(children) && typeof children[0] === 'string') {
      child = <Text style={styles.text}>{children}</Text>;
    } else {
      child = children;
    }
    return (
      <View style={styles.content}>
        <ActivityIndicator {...loadingProps}/>
        {child}
      </View>
    );
  }

  render() {
    const {
      style, children,
      isLoadingDialog,
      loadingProps,
      ...other
    } = this.props;

    const innerStyle = [
      getWindowSize(),
      isLoadingDialog ? styles.loadingContainer : {},
      style
    ];

    return (
      <Modal {...other}>
        <View style={innerStyle}>
          {isLoadingDialog ? this.renderLoading({
            children,
            loadingProps
          }) : children}
        </View>
      </Modal>
    );
  }
}


// noinspection Eslint
export default createRootView(Dialog);
{'fraction_non_alphanumeric': 0.13083273510409188, 'fraction_numerical': 0.008255563531945441, 'mean_word_length': 2.4316502463054186, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '7496139', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1700, 'n_words': 357}