<commit_before>import React from 'react-native';

import Ionicon from 'react-native-vector-icons/Ionicons'

import { getNavigationDelegate } from './utils';

const {
  View,
  Text,
  TouchableOpacity,
  Navigator,
  Animated,
  StyleSheet,
  PropTypes,
  Dimensions,
  Platform,
} = React;

const IS_IOS = Platform.OS === 'ios';

const NAV_BAR_STYLES = Navigator.NavigationBar.Styles;
const NAV_BAR_DEFAULT_BACKGROUND_COLOR = 'white';
const NAV_BAR_DEFAULT_TINT_COLOR = 'black';
const NAV_HEIGHT = NAV_BAR_STYLES.General.TotalNavHeight;
const SCREEN_WIDTH = Dimensions.get('window').width;
const LEFT_PART_WIDTH = IS_IOS ? SCREEN_WIDTH / 4 : 48;
const RIGHT_PART_WIDTH = SCREEN_WIDTH / (IS_IOS ? 4 : 3);
const TITLE_PART_WIDTH = SCREEN_WIDTH - LEFT_PART_WIDTH - RIGHT_PART_WIDTH;
const DEFAULT_IOS_BACK_ICON = 'ios-arrow-back';
const DEFAULT_ANDROID_BACK_ICON = 'android-arrow-back';

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

    this.state = {
      opacity: new Animated.Value(props.isHiddenOnInit ? 0 : 1),
      y: new Animated.Value(props.isHiddenOnInit ? -NAV_HEIGHT : 0),
      animationProgress: new Animated.Value(0),
      animationFromIndex: 0,
      animationToIndex: 0,
      prevTitleXPos: 0,
      prevTitleWidth: 0,
      backIconWidth: 0,
    }
  }

  _setTitle(title) {
    const currentRoute = this.props.navState.routeStack.slice(-1)[0];
    const navigationDelegate = getNavigationDelegate(currentRoute.component);
    const oldTitle =
      navigationDelegate &&
      navigationDelegate.getNavBarTitle &&
      navigationDelegate.getNavBarTitle();

    if (oldTitle) {
      let newTitle = null;

      if (typeof oldTitle === 'object') {
        if (React.isValidElement(oldTitle)) {
          newTitle = React.cloneElement(oldTitle, {
            text: title,
            title,
          });

          navigationDelegate
            .getNavBarTitle = () => newTitle;
        } else {
          navigationDelegate
            .getNavBarTitle = () => Object.assign({}, oldTitle, {
              text: title,
            });
        }
      }
    } else {
      if (navigationDelegate) {
        navigationDelegate.getNavBarTitle = () => title;
      }
    }
  }

  _setLeftBtn(btn) {
    const currentRoute = this.props.navState.routeStack.slice(-1)[0];
    const navigationDelegate = getNavigationDelegate(currentRoute.component);

    if (navigationDelegate) {
      navigationDelegate.getNavBarLeftBtn = () => btn;
    }
  }

  _setRightBtn(btn) {
    const currentRoute = this.props.navState.routeStack.slice(-1)[0];
    const navigationDelegate = getNavigationDelegate(currentRoute.component);

    if (navigationDelegate) {
      navigationDelegate.getNavBarRightBtn = () => btn;
    }
  }

  updateUI(ui) {
    ui.title !== undefined && this._setTitle(ui.title);
    ui.leftBtn !== undefined && this._setLeftBtn(ui.leftBtn);
    ui.rightBtn !== undefined && this._setRightBtn(ui.rightBtn);

    this.forceUpdate();
  }

  updateProgress(progress, fromIndex, toIndex) {
    this.state = Object.assign({}, this.state, {
      animationFromIndex: fromIndex,
      animationToIndex: toIndex,
    })

    this.state.animationProgress.setValue(progress);

    this.forceUpdate();
  }

  immediatelyRefresh() {
    this.setState({
      opacity: new Animated.Value(this.props.isHiddenOnInit ? 0 : 1),
      y: new Animated.Value(this.props.isHiddenOnInit ? -NAV_HEIGHT : 0),
      animationProgress: new Animated.Value(0),
      animationFromIndex: 0,
      animationToIndex: 0,
      prevTitleXPos: 0,
      prevTitleWidth: 0,
      backIconWidth: 0,
    });
  }

  show(type = 'fade') {
    if (type === 'fade') {
      this.state.y.setValue(0);
      this.state.opacity.setValue(0);

      Animated.timing(this.state.opacity, {
        toValue: 1,
        duration: 200,
      }).start(() => {
        this.state.opacity.setValue(1);
      });
    } else if (type === 'slide') {
      this.state.opacity.setValue(1);
      this.state.y.setValue(-NAV_HEIGHT);

      Animated.timing(this.state.y, {
        toValue: 0,
        duration: 100,
      }).start();
    }
  }

  hide(type = 'fade') {
    if (type === 'fade') {
      Animated.timing(this.state.opacity, {
        toValue: 0,
        duration: 200,
      }).start(() => {
        this.state.y.setValue(-NAV_HEIGHT);
      });
    } else if (type === 'slide') {
      Animated.timing(this.state.y, {
        toValue: -NAV_HEIGHT,
        duration: 100,
      }).start(() => {
        this.state.opacity.setValue(0);
      });<commit_msg>Fixed navbar fade animation #2<commit_after>import React from 'react-native';

import Ionicon from 'react-native-vector-icons/Ionicons'

import { getNavigationDelegate } from './utils';

const {
  View,
  Text,
  TouchableOpacity,
  Navigator,
  Animated,
  StyleSheet,
  PropTypes,
  Dimensions,
  Platform,
} = React;

const IS_IOS = Platform.OS === 'ios';

const NAV_BAR_STYLES = Navigator.NavigationBar.Styles;
const NAV_BAR_DEFAULT_BACKGROUND_COLOR = 'white';
const NAV_BAR_DEFAULT_TINT_COLOR = 'black';
const NAV_HEIGHT = NAV_BAR_STYLES.General.TotalNavHeight;
const SCREEN_WIDTH = Dimensions.get('window').width;
const LEFT_PART_WIDTH = IS_IOS ? SCREEN_WIDTH / 4 : 48;
const RIGHT_PART_WIDTH = SCREEN_WIDTH / (IS_IOS ? 4 : 3);
const TITLE_PART_WIDTH = SCREEN_WIDTH - LEFT_PART_WIDTH - RIGHT_PART_WIDTH;
const DEFAULT_IOS_BACK_ICON = 'ios-arrow-back';
const DEFAULT_ANDROID_BACK_ICON = 'android-arrow-back';

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

    this.state = {
      opacity: new Animated.Value(props.isHiddenOnInit ? 0 : 1),
      y: new Animated.Value(props.isHiddenOnInit ? -NAV_HEIGHT : 0),
      animationProgress: new Animated.Value(0),
      animationFromIndex: 0,
      animationToIndex: 0,
      prevTitleXPos: 0,
      prevTitleWidth: 0,
      backIconWidth: 0,
    }
  }

  _setTitle(title) {
    const currentRoute = this.props.navState.routeStack.slice(-1)[0];
    const navigationDelegate = getNavigationDelegate(currentRoute.component);
    const oldTitle =
      navigationDelegate &&
      navigationDelegate.getNavBarTitle &&
      navigationDelegate.getNavBarTitle();

    if (oldTitle) {
      let newTitle = null;

      if (typeof oldTitle === 'object') {
        if (React.isValidElement(oldTitle)) {
          newTitle = React.cloneElement(oldTitle, {
            text: title,
            title,
          });

          navigationDelegate
            .getNavBarTitle = () => newTitle;
        } else {
          navigationDelegate
            .getNavBarTitle = () => Object.assign({}, oldTitle, {
              text: title,
            });
        }
      }
    } else {
      if (navigationDelegate) {
        navigationDelegate.getNavBarTitle = () => title;
      }
    }
  }

  _setLeftBtn(btn) {
    const currentRoute = this.props.navState.routeStack.slice(-1)[0];
    const navigationDelegate = getNavigationDelegate(currentRoute.component);

    if (navigationDelegate) {
      navigationDelegate.getNavBarLeftBtn = () => btn;
    }
  }

  _setRightBtn(btn) {
    const currentRoute = this.props.navState.routeStack.slice(-1)[0];
    const navigationDelegate = getNavigationDelegate(currentRoute.component);

    if (navigationDelegate) {
      navigationDelegate.getNavBarRightBtn = () => btn;
    }
  }

  updateUI(ui) {
    ui.title !== undefined && this._setTitle(ui.title);
    ui.leftBtn !== undefined && this._setLeftBtn(ui.leftBtn);
    ui.rightBtn !== undefined && this._setRightBtn(ui.rightBtn);

    this.forceUpdate();
  }

  updateProgress(progress, fromIndex, toIndex) {
    this.state = Object.assign({}, this.state, {
      animationFromIndex: fromIndex,
      animationToIndex: toIndex,
    })

    this.state.animationProgress.setValue(progress);

    this.forceUpdate();
  }

  immediatelyRefresh() {
    this.setState({
      opacity: new Animated.Value(this.props.isHiddenOnInit ? 0 : 1),
      y: new Animated.Value(this.props.isHiddenOnInit ? -NAV_HEIGHT : 0),
      animationProgress: new Animated.Value(0),
      animationFromIndex: 0,
      animationToIndex: 0,
      prevTitleXPos: 0,
      prevTitleWidth: 0,
      backIconWidth: 0,
    });
  }

  show(type = 'fade') {
    if (type === 'fade') {
      this.state.y.setValue(0);

      Animated.timing(this.state.opacity, {
        toValue: 1,
        duration: 200,
      }).start();
    } else if (type === 'slide') {
      this.state.opacity.setValue(1);

      Animated.timing(this.state.y, {
        toValue: 0,
        duration: 100,
      }).start();
    }
  }

  hide(type = 'fade') {
    if (type === 'fade') {
      Animated.timing(this.state.opacity, {
        toValue: 0,
        duration: 200,
      }).start(() => {
        this.state.y.setValue(-NAV_HEIGHT);
      });
    } else if (type === 'slide') {
      Animated.timing(this.state.y, {
        toValue: -NAV_HEIGHT,
        duration: 100,
      }).start(() => {
        this.state.opacity.setValue(0);
      });
{'fraction_non_alphanumeric': 0.12898230088495574, 'fraction_numerical': 0.010730088495575222, 'mean_word_length': 2.774947807933194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '3150409', 'n_tokens_mistral': 2980, 'n_tokens_neox': 2840, 'n_words': 519}