Skip to content

Conversation

@jgonet
Copy link
Member

@jgonet jgonet commented Feb 11, 2021

Description

Fixes #1338.

Having different extensions (e.g. .ts and .tsx) caused Metro to prioritize one over another. This prevented .android.tsx from being loaded, as .ts was loaded first.

Test plan

Wrapped example app with gestureHandlerRootHOC in index.js and verified it on Android.

Tested on this code snippet:
import React, {Component} from 'react';
import {
  SafeAreaView,
  StyleSheet,
  StatusBar,
  ViewStyle,
  StyleProp,
  Animated,
} from 'react-native';
import {
  PanGestureHandler,
  PanGestureHandlerGestureEvent,
  PanGestureHandlerStateChangeEvent,
  State,
  TouchableOpacity,
} from 'react-native-gesture-handler';

type DraggableBoxProps = {
  minDist?: number;
  boxStyle?: StyleProp<ViewStyle>;
};
export class DraggableBox extends Component<DraggableBoxProps> {
  private translateX: Animated.Value;
  private translateY: Animated.Value;
  private lastOffset: {x: number; y: number};
  private onGestureEvent: (event: PanGestureHandlerGestureEvent) => void;
  constructor(props: DraggableBoxProps) {
    super(props);
    this.translateX = new Animated.Value(0);
    this.translateY = new Animated.Value(0);
    this.lastOffset = {x: 0, y: 0};
    this.onGestureEvent = Animated.event(
      [
        {
          nativeEvent: {
            translationX: this.translateX,
            translationY: this.translateY,
          },
        },
      ],
      {useNativeDriver: true},
    );
  }
  private onHandlerStateChange = (event: PanGestureHandlerStateChangeEvent) => {
    console.log('state');

    if (event.nativeEvent.oldState === State.ACTIVE) {
      this.lastOffset.x += event.nativeEvent.translationX;
      this.lastOffset.y += event.nativeEvent.translationY;
      this.translateX.setOffset(this.lastOffset.x);
      this.translateX.setValue(0);
      this.translateY.setOffset(this.lastOffset.y);
      this.translateY.setValue(0);
    }
  };
  render() {
    return (
      <PanGestureHandler
        {...this.props}
        onGestureEvent={this.onGestureEvent}
        onHandlerStateChange={this.onHandlerStateChange}
        minDist={this.props.minDist}>
        <Animated.View
          style={[
            styles.box,
            {
              transform: [
                {translateX: this.translateX},
                {translateY: this.translateY},
              ],
            },
            this.props.boxStyle,
          ]}
        />
      </PanGestureHandler>
    );
  }
}

const App = () => {
  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView>
        <DraggableBox />
        <TouchableOpacity
          disabled={false}
          style={{width: 100, height: 50, backgroundColor: 'red'}}
          onPress={() => console.log('rngh')}
        />
      </SafeAreaView>
    </>
  );
};

const styles = StyleSheet.create({
  box: {
    width: 150,
    height: 150,
    alignSelf: 'center',
    backgroundColor: 'plum',
    margin: 10,
    zIndex: 200,
  },
});

export default App;

Having different extensions (e.g. .ts and .tsx) caused Metro to prioritize one over another. This prevented .android.tsx from being loaded, as .ts was loaded first.
Copy link
Contributor

@mrousavy mrousavy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #1338 👍

@jgonet jgonet merged commit d4ed1c6 into master Feb 12, 2021
@jgonet jgonet deleted the @kuba/fix-hoc branch February 12, 2021 10:40
braincore pushed a commit to braincore/react-native-gesture-handler that referenced this pull request Mar 4, 2021
Having different extensions (e.g. .ts and .tsx) caused Metro to prioritize one over another. This prevented .android.tsx from being loaded, as .ts was loaded first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native Touchable* not working anymore (1.10.0)

3 participants