<commit_before>/* @flow */

import React, { PureComponent, PropTypes } from 'react';
import {
  Platform,
  View,
  StyleSheet,
} from 'react-native';
import TabViewTransitioner from './TabViewTransitioner';
import { NavigationStatePropType } from './TabViewPropTypes';
import type { Scene, SceneRendererProps } from './TabViewTypeDefinitions';
import type { TransitionerProps } from './TabViewTransitionerTypes';

const styles = StyleSheet.create({
  container: {
    flex: 1,
    overflow: 'hidden',
  },
});

type DefaultProps = {
  renderPager: (props: SceneRendererProps) => React.Element<*>;
}

type Props = TransitionerProps & {
  renderPager: (props: SceneRendererProps) => React.Element<*>;
  renderScene: (props: SceneRendererProps & Scene) => ?React.Element<*>;
  renderHeader?: (props: SceneRendererProps) => ?React.Element<*>;
  renderFooter?: (props: SceneRendererProps) => ?React.Element<*>;
  lazy?: boolean;
}

type State = {
  loaded: Array<number>;
}

let TabViewPager;

switch (Platform.OS) {
case 'android':
  TabViewPager = require('./TabViewPagerAndroid').default;
  break;
case 'ios':
  TabViewPager = require('./TabViewPagerScroll').default;
  break;
default:
  TabViewPager = require('./TabViewPagerPan').default;
  break;
}

export default class TabViewAnimated extends PureComponent<DefaultProps, Props, State> {
  static propTypes = {
    navigationState: NavigationStatePropType.isRequired,
    renderPager: PropTypes.func.isRequired,
    renderScene: PropTypes.func.isRequired,
    renderHeader: PropTypes.func,
    renderFooter: PropTypes.func,
    onChangePosition: PropTypes.func,
    shouldOptimizeUpdates: PropTypes.bool,
    lazy: PropTypes.bool,
  };

  static defaultProps = {
    renderPager: (props: SceneRendererProps) => <TabViewPager {...props} />,
  };

  constructor(props: Props) {
    super(props);

    this.state = {
      loaded: [ this.props.navigationState.index ],
    };
  }

  state: State;

  _renderScene = (props: SceneRendererProps & Scene) => {
    const { renderScene, navigationState, lazy } = this.props;
    const { loaded } = this.state;
    if (lazy) {
      if (loaded.includes(navigationState.routes.indexOf(props.route))) {
        return renderScene(props);
      }
      return null;
    }
    return renderScene(props);
  };

  _renderItems = (props: SceneRendererProps) => {
    const { renderPager, renderHeader, renderFooter } = this.props;
    const { navigationState, layout } = props;
    const currentRoute = navigationState.routes[navigationState.index];

    return (
      <View style={styles.container}>
        {renderHeader && renderHeader(props)}
        {renderPager({
          ...props,
          children: layout.width ? navigationState.routes.map((route, index) => (
            <View key={route.key} style={{ width: layout.width }}>
              {this._renderScene({
                ...props,
                route,
                index,
                focused: index === props.navigationState.index,
              })}
            </View>
          )) : (
            <View key={currentRoute.key} style={styles.container}>
              {this._renderScene({
                ...props,
                route: currentRoute,
                index: navigationState.index,
                focused: true,
              })}
            </View><commit_msg>fix: hide overflow for individual tabs<commit_after>/* @flow */

import React, { PureComponent, PropTypes } from 'react';
import {
  Platform,
  View,
  StyleSheet,
} from 'react-native';
import TabViewTransitioner from './TabViewTransitioner';
import { NavigationStatePropType } from './TabViewPropTypes';
import type { Scene, SceneRendererProps } from './TabViewTypeDefinitions';
import type { TransitionerProps } from './TabViewTransitionerTypes';

const styles = StyleSheet.create({
  container: {
    flex: 1,
    overflow: 'hidden',
  },
});

type DefaultProps = {
  renderPager: (props: SceneRendererProps) => React.Element<*>;
}

type Props = TransitionerProps & {
  renderPager: (props: SceneRendererProps) => React.Element<*>;
  renderScene: (props: SceneRendererProps & Scene) => ?React.Element<*>;
  renderHeader?: (props: SceneRendererProps) => ?React.Element<*>;
  renderFooter?: (props: SceneRendererProps) => ?React.Element<*>;
  lazy?: boolean;
}

type State = {
  loaded: Array<number>;
}

let TabViewPager;

switch (Platform.OS) {
case 'android':
  TabViewPager = require('./TabViewPagerAndroid').default;
  break;
case 'ios':
  TabViewPager = require('./TabViewPagerScroll').default;
  break;
default:
  TabViewPager = require('./TabViewPagerPan').default;
  break;
}

export default class TabViewAnimated extends PureComponent<DefaultProps, Props, State> {
  static propTypes = {
    navigationState: NavigationStatePropType.isRequired,
    renderPager: PropTypes.func.isRequired,
    renderScene: PropTypes.func.isRequired,
    renderHeader: PropTypes.func,
    renderFooter: PropTypes.func,
    onChangePosition: PropTypes.func,
    shouldOptimizeUpdates: PropTypes.bool,
    lazy: PropTypes.bool,
  };

  static defaultProps = {
    renderPager: (props: SceneRendererProps) => <TabViewPager {...props} />,
  };

  constructor(props: Props) {
    super(props);

    this.state = {
      loaded: [ this.props.navigationState.index ],
    };
  }

  state: State;

  _renderScene = (props: SceneRendererProps & Scene) => {
    const { renderScene, navigationState, lazy } = this.props;
    const { loaded } = this.state;
    if (lazy) {
      if (loaded.includes(navigationState.routes.indexOf(props.route))) {
        return renderScene(props);
      }
      return null;
    }
    return renderScene(props);
  };

  _renderItems = (props: SceneRendererProps) => {
    const { renderPager, renderHeader, renderFooter } = this.props;
    const { navigationState, layout } = props;
    const currentRoute = navigationState.routes[navigationState.index];

    return (
      <View style={styles.container}>
        {renderHeader && renderHeader(props)}
        {renderPager({
          ...props,
          children: layout.width ? navigationState.routes.map((route, index) => (
            <View key={route.key} style={{ width: layout.width, overflow: 'hidden' }}>
              {this._renderScene({
                ...props,
                route,
                index,
                focused: index === props.navigationState.index,
              })}
            </View>
          )) : (
            <View key={currentRoute.key} style={styles.container}>
              {this._renderScene({
                ...props,
                route: currentRoute,
                index: navigationState.index,
                focused: true,
              })}
            </View>
{'fraction_non_alphanumeric': 0.13088694101916507, 'fraction_numerical': 0.0002971326697370376, 'mean_word_length': 2.9414519906323187, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 47, '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': '6777912', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1925, 'n_words': 416}