<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import NavBar from './NavBar';
import Scene from './Scene';
import { getNavigationDelegate, replaceInstanceEventedProps } from './utils';
import FBNavigator from './FBNavigator';

import {
  StyleSheet,
  Platform,
  BackHandler,
  ViewPropTypes,
} from 'react-native';

const VALID_EVENTED_PROPS = [
  'onPress',
  'onValueChange',
  'onChange',
  'onSelection',
  'onChangeText',
  'onBlur',
  'onFocus',
  'onSelectionChange',
  'onSubmitEditing',
];

export default class YANavigator extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      shouldHandleAndroidBack: props.shouldHandleAndroidBack,
    }
  }

  componentDidMount() {
    const navigatorMethods = [
      'getCurrentRoutes',
      'jumpBack',
      'jumpForward',
      'jumpTo',
      'push',
      'pop',
      'popN',
      'replace',
      'replaceAtIndex',
      'replacePrevious',
      'replacePreviousAndPop',
      'resetTo',
      'immediatelyResetRouteStack',
      'popToRoute',
      'popToTop',
    ];

    navigatorMethods.forEach((method) => {
      this[method] = this.refs.navigator[method];
    })

    this.refs.navigator.setShouldHandleAndroidBack = this.setShouldHandleAndroidBack.bind(this);

    if (Platform.OS === 'android') {
      this._backPressSub = BackHandler.addEventListener('hardwareBackPress', () => {
        if (!this.state.shouldHandleAndroidBack) return false;

        const { navigator } = this.refs;
        const navState = navigator.state;
        const presentedComponent =
          navState.routeStack[navState.presentedIndex].component;
        const navigationDelegate = getNavigationDelegate(presentedComponent);

        if (navigationDelegate && navigationDelegate.onAndroidBackPress) {

          navigationDelegate.onAndroidBackPress(navigator);

          return true;
        } else if (navState.routeStack.length > 1) {
          navigator.pop();

          return true;
        }

       return false;
      });
    }
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.shouldHandleAndroidBack !== this.props.shouldHandleAndroidBack) {
      this.setState({
        shouldHandleAndroidBack: nextProps.shouldHandleAndroidBack,
      });
    }
  }

  componentWillUnmount() {
    if (Platform.OS === 'android') {
      this._backPressSub.remove();
      this._backPressSub = null;
    }
  }

  setShouldHandleAndroidBack(should) {
    this.setState({
      shouldHandleAndroidBack: should,
    });
  }

  _renderScene = (route, navigator) => {
    let Component;

    const { eachSceneProps } = this.props;

    if (typeof route.component === 'object') {
      Component = React.cloneElement(route.component, {
        navigator,<commit_msg>Re-render inital route if it was passed<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import NavBar from './NavBar';
import Scene from './Scene';
import { getNavigationDelegate, replaceInstanceEventedProps } from './utils';
import FBNavigator from './FBNavigator';

import {
  StyleSheet,
  Platform,
  BackHandler,
  ViewPropTypes,
} from 'react-native';

const VALID_EVENTED_PROPS = [
  'onPress',
  'onValueChange',
  'onChange',
  'onSelection',
  'onChangeText',
  'onBlur',
  'onFocus',
  'onSelectionChange',
  'onSubmitEditing',
];

export default class YANavigator extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      shouldHandleAndroidBack: props.shouldHandleAndroidBack,
    }
  }

  componentDidMount() {
    const navigatorMethods = [
      'getCurrentRoutes',
      'jumpBack',
      'jumpForward',
      'jumpTo',
      'push',
      'pop',
      'popN',
      'replace',
      'replaceAtIndex',
      'replacePrevious',
      'replacePreviousAndPop',
      'resetTo',
      'immediatelyResetRouteStack',
      'popToRoute',
      'popToTop',
    ];

    navigatorMethods.forEach((method) => {
      this[method] = this.refs.navigator[method];
    })

    this.refs.navigator.setShouldHandleAndroidBack = this.setShouldHandleAndroidBack.bind(this);

    if (Platform.OS === 'android') {
      this._backPressSub = BackHandler.addEventListener('hardwareBackPress', () => {
        if (!this.state.shouldHandleAndroidBack) return false;

        const { navigator } = this.refs;
        const navState = navigator.state;
        const presentedComponent =
          navState.routeStack[navState.presentedIndex].component;
        const navigationDelegate = getNavigationDelegate(presentedComponent);

        if (navigationDelegate && navigationDelegate.onAndroidBackPress) {

          navigationDelegate.onAndroidBackPress(navigator);

          return true;
        } else if (navState.routeStack.length > 1) {
          navigator.pop();

          return true;
        }

       return false;
      });
    }
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.shouldHandleAndroidBack !== this.props.shouldHandleAndroidBack) {
      this.setState({
        shouldHandleAndroidBack: nextProps.shouldHandleAndroidBack,
      });
    }

    if (nextProps.initialRoute.component !== this.props.initialRoute.component) {
      this.refs.navigator.resetTo(nextProps.initialRoute);
    }
  }

  componentWillUnmount() {
    if (Platform.OS === 'android') {
      this._backPressSub.remove();
      this._backPressSub = null;
    }
  }

  setShouldHandleAndroidBack(should) {
    this.setState({
      shouldHandleAndroidBack: should,
    });
  }

  _renderScene = (route, navigator) => {
    let Component;

    const { eachSceneProps } = this.props;

    if (typeof route.component === 'object') {
      Component = React.cloneElement(route.component, {
        navigator,
{'fraction_non_alphanumeric': 0.11809656130600903, 'fraction_numerical': 0.0003473428273706148, 'mean_word_length': 3.035739313244569, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1295193', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1644, 'n_words': 301}