<commit_before>/**
 *
 * @license
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @author <NAME>
 * @created 2016-10-19
 * @file Find.js
 * @description Navigator for managing views for finding rooms on campus.
 *
 * @flow
 */
'use strict';

// React imports
import React from 'react';
import {
  Navigator,
  StyleSheet,
  Text,
  View,
} from 'react-native';

// Redux imports
import {connect} from 'react-redux';
import {
  setHeaderTitle,
  setShowBack,
  setShowSearch,
  switchFindView,
} from 'actions';

// Type imports
import type {
  Route,
  Tab,
} from 'types';

// Type definition for component props.
type Props = {
  appTab: Tab,                              // The current tab the app is showing
  backCount: number,                        // Number of times the user has requested back navigation
  onBackNavigation: (view: number) => void, // Callback when user pops the stacks
  view: number,                             // The current view
};

// Imports
import * as Constants from 'Constants';

// Screen imports
import Building from './Building';
import Home from './Home';
// const NavigationHome = require('NavigationHome');

class Find extends React.Component {

  /**
   * Properties this component expects to be provided by its parent.
   */
  props: Props;

  /**
   * Adds a listener for navigation events.
   */
  componentDidMount(): void {
    this.refs.Navigator.navigationContext.addListener('didfocus', this._handleNavigationEvent.bind(this));
  }

  /**
   * Present the updated view.
   *
   * @param {Props} nextProps the new props being received
   */
  componentWillReceiveProps(nextProps: Props): void {
    if (nextProps.view != this.props.view) {
      const currentRoutes = this.refs.Navigator.getCurrentRoutes();
      if (currentRoutes != null && currentRoutes.length > 0
          && nextProps.view === currentRoutes[currentRoutes.length - 1].id) {
        return;
      }
      this.refs.Navigator.push({id: nextProps.view});
    } else if (nextProps.appTab === 'find' && nextProps.backCount != this.props.backCount) {
      this.refs.Navigator.pop();
    }
  }

  /**
   * Sets the transition between two views in the navigator.
   *<commit_msg>Pop to building view instead of pushing another<commit_after>/**
 *
 * @license
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @author <NAME>
 * @created 2016-10-19
 * @file Find.js
 * @description Navigator for managing views for finding rooms on campus.
 *
 * @flow
 */
'use strict';

// React imports
import React from 'react';
import {
  Navigator,
  StyleSheet,
  Text,
  View,
} from 'react-native';

// Redux imports
import {connect} from 'react-redux';
import {
  setHeaderTitle,
  setShowBack,
  setShowSearch,
  switchFindView,
} from 'actions';

// Type imports
import type {
  Route,
  Tab,
} from 'types';

// Type definition for component props.
type Props = {
  appTab: Tab,                              // The current tab the app is showing
  backCount: number,                        // Number of times the user has requested back navigation
  onBackNavigation: (view: number) => void, // Callback when user pops the stacks
  view: number,                             // The current view
};

// Imports
import * as Constants from 'Constants';

// Screen imports
import Building from './Building';
import Home from './Home';
// const NavigationHome = require('NavigationHome');

class Find extends React.Component {

  /**
   * Properties this component expects to be provided by its parent.
   */
  props: Props;

  /**
   * Adds a listener for navigation events.
   */
  componentDidMount(): void {
    this.refs.Navigator.navigationContext.addListener('didfocus', this._handleNavigationEvent.bind(this));
  }

  /**
   * Present the updated view.
   *
   * @param {Props} nextProps the new props being received
   */
  componentWillReceiveProps(nextProps: Props): void {
    if (nextProps.view != this.props.view) {
      const currentRoutes = this.refs.Navigator.getCurrentRoutes();
      for (let i = 0; i < currentRoutes.length; i++) {
        if (nextProps.view === currentRoutes[i].id) {
          this.refs.Navigator.popToRoute(currentRoutes[i]);
          return;
        }
      }
      this.refs.Navigator.push({id: nextProps.view});
    } else if (nextProps.appTab === 'find' && nextProps.backCount != this.props.backCount) {
      this.refs.Navigator.pop();
    }
  }

  /**
   * Sets the transition between two views in the navigator.
   *
{'fraction_non_alphanumeric': 0.10978907517577069, 'fraction_numerical': 0.006309716964124752, 'mean_word_length': 2.9153140437544107, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3922042', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1547, 'n_words': 554}