<commit_before>// @flow

import type {
  NavigationScreenProp,
  NavigationState,
  NavigationDescriptor,
  NavigationStackScreenOptions,
  NavigationRouteConfigMap,
  NavigationTransitionProps,
  NavigationScene,
} from '@react-navigation/core';
import type { 
  StackNavigatorConfig,
} from 'react-navigation';

import * as React from 'react';
import {
  View,
  StyleSheet,
  Animated as BaseAnimated,
  Easing as BaseEasing,
} from 'react-native';
import {
  StackRouter,
  createNavigator,
  StackActions,
} from '@react-navigation/core';
import { Transitioner } from 'react-navigation-stack';
import Animated, { Easing } from 'react-native-reanimated';

const LightboxPositionContext: React.Context<Animated.Value>
  = React.createContext(null);

function createLightboxNavigator(
  routeConfigMap: NavigationRouteConfigMap,
  stackConfig: StackNavigatorConfig = {},
) {
  const {
    initialRouteName,
    initialRouteParams,
    paths,
    defaultNavigationOptions,
    initialRouteKey,
  } = stackConfig;
  const stackRouterConfig = {
    initialRouteName,
    initialRouteParams,
    paths,
    defaultNavigationOptions,
    initialRouteKey,
  };
  return createNavigator<
    NavigationStackScreenOptions,
    NavigationState,
    StackNavigatorConfig,
  >(
    Lightbox,
    StackRouter(routeConfigMap, stackRouterConfig),
    stackConfig,
  );
}

type Props = $ReadOnly<{
  navigation: NavigationScreenProp<NavigationState>,
  descriptors: { [key: string]: NavigationDescriptor },
  navigationConfig: StackNavigatorConfig,
}>;
class Lightbox extends React.PureComponent<Props> {

  position: Animated.Value;

  constructor(props: Props) {
    super(props);
    this.position = new Animated.Value(props.navigation.state.index);
  }

  render() {
    return (
      <Transitioner
        render={this.renderScenes}
        configureTransition={this.configureTransition}
        navigation={this.props.navigation}
        descriptors={this.props.descriptors}
        onTransitionStart={this.onTransitionStart}
        onTransitionEnd={this.onTransitionEnd}
      />
    );
  }

  configureTransition = () => ({
    duration: 250,
    easing: BaseEasing.inOut(BaseEasing.ease),
    timing: BaseAnimated.timing,
    useNativeDriver: true,
  })

  onTransitionStart = (transitionProps: NavigationTransitionProps) => {
    const { index } = transitionProps.navigation.state;
    Animated.timing(
      this.position,
      {
        duration: 250,
        easing: Easing.inOut(Easing.ease),
        toValue: index,
      },
    ).start();
  }

  onTransitionEnd = (transitionProps: NavigationTransitionProps) => {
    if (!transitionProps.navigation.state.isTransitioning) {
      return;
    }
    const { navigation } = this.props;
    const transitionDestKey = transitionProps.scene.route.key;
    const isCurrentKey =
      navigation.state.routes[navigation.state.index].key === transitionDestKey;
    if (!isCurrentKey) {
      return;
    }
    navigation.dispatch(
      StackActions.completeTransition({ toChildKey: transitionDestKey }),
    );
  }

  renderScenes = (transitionProps: NavigationTransitionProps) => {
    const { scenes } = transitionProps;
    const renderScene =
      (scene: NavigationScene) => this.renderScene(
        scene,
        transitionProps,
      );
    return (
      <LightboxPositionContext.Provider value={this.position}>
        {scenes.map(renderScene)}
      </LightboxPositionContext.Provider>
    );
  }

  renderScene(scene: NavigationScene, transitionProps: NavigationTransitionProps) {
    if (!scene.descriptor) {
      return null;
    }
    const { navigation, getComponent } = scene.descriptor;
    const SceneComponent = getComponent();
    return (
      <View style={styles.scene} key={scene.key}>
        <SceneComponent
          navigation={navigation}
          scene={scene}
          transitionProps={transitionProps}
          position={this.position}
        />
      </View>
    );
  }
<commit_msg>[native] Wrap inactive lightbox scenes in pointerEvents="none"<commit_after>// @flow

import type {
  NavigationScreenProp,
  NavigationState,
  NavigationDescriptor,
  NavigationStackScreenOptions,
  NavigationRouteConfigMap,
  NavigationTransitionProps,
  NavigationScene,
} from '@react-navigation/core';
import type { 
  StackNavigatorConfig,
} from 'react-navigation';

import * as React from 'react';
import {
  View,
  StyleSheet,
  Animated as BaseAnimated,
  Easing as BaseEasing,
} from 'react-native';
import {
  StackRouter,
  createNavigator,
  StackActions,
} from '@react-navigation/core';
import { Transitioner } from 'react-navigation-stack';
import Animated, { Easing } from 'react-native-reanimated';

const LightboxPositionContext: React.Context<Animated.Value>
  = React.createContext(null);

function createLightboxNavigator(
  routeConfigMap: NavigationRouteConfigMap,
  stackConfig: StackNavigatorConfig = {},
) {
  const {
    initialRouteName,
    initialRouteParams,
    paths,
    defaultNavigationOptions,
    initialRouteKey,
  } = stackConfig;
  const stackRouterConfig = {
    initialRouteName,
    initialRouteParams,
    paths,
    defaultNavigationOptions,
    initialRouteKey,
  };
  return createNavigator<
    NavigationStackScreenOptions,
    NavigationState,
    StackNavigatorConfig,
  >(
    Lightbox,
    StackRouter(routeConfigMap, stackRouterConfig),
    stackConfig,
  );
}

type Props = $ReadOnly<{
  navigation: NavigationScreenProp<NavigationState>,
  descriptors: { [key: string]: NavigationDescriptor },
  navigationConfig: StackNavigatorConfig,
}>;
class Lightbox extends React.PureComponent<Props> {

  position: Animated.Value;

  constructor(props: Props) {
    super(props);
    this.position = new Animated.Value(props.navigation.state.index);
  }

  render() {
    return (
      <Transitioner
        render={this.renderScenes}
        configureTransition={this.configureTransition}
        navigation={this.props.navigation}
        descriptors={this.props.descriptors}
        onTransitionStart={this.onTransitionStart}
        onTransitionEnd={this.onTransitionEnd}
      />
    );
  }

  configureTransition = () => ({
    duration: 250,
    easing: BaseEasing.inOut(BaseEasing.ease),
    timing: BaseAnimated.timing,
    useNativeDriver: true,
  })

  onTransitionStart = (transitionProps: NavigationTransitionProps) => {
    const { index } = transitionProps.navigation.state;
    Animated.timing(
      this.position,
      {
        duration: 250,
        easing: Easing.inOut(Easing.ease),
        toValue: index,
      },
    ).start();
  }

  onTransitionEnd = (transitionProps: NavigationTransitionProps) => {
    if (!transitionProps.navigation.state.isTransitioning) {
      return;
    }
    const { navigation } = this.props;
    const transitionDestKey = transitionProps.scene.route.key;
    const isCurrentKey =
      navigation.state.routes[navigation.state.index].key === transitionDestKey;
    if (!isCurrentKey) {
      return;
    }
    navigation.dispatch(
      StackActions.completeTransition({ toChildKey: transitionDestKey }),
    );
  }

  renderScenes = (transitionProps: NavigationTransitionProps) => {
    const { scenes } = transitionProps;
    const renderScene =
      (scene: NavigationScene) => this.renderScene(
        scene,
        transitionProps,
      );
    return (
      <LightboxPositionContext.Provider value={this.position}>
        {scenes.map(renderScene)}
      </LightboxPositionContext.Provider>
    );
  }

  renderScene(scene: NavigationScene, transitionProps: NavigationTransitionProps) {
    if (!scene.descriptor) {
      return null;
    }
    const { navigation, getComponent } = scene.descriptor;
    const SceneComponent = getComponent();
    const pointerEvents = scene.isActive ? "auto" : "none";
    return (
      <View style={styles.scene} key={scene.key} pointerEvents={pointerEvents}>
        <SceneComponent
          navigation={navigation}
          scene={scene}
          transitionProps={transitionProps}
          position={this.position}
        />
      </View>
    );
  }

{'fraction_non_alphanumeric': 0.10476190476190476, 'fraction_numerical': 0.001484230055658627, 'mean_word_length': 3.4550964187327824, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 35, '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': '4541601', 'n_tokens_mistral': 2314, 'n_tokens_neox': 2253, 'n_words': 420}