Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove GestureHandlerRootView.android.expo.tsx #1383

Merged
merged 1 commit into from
Feb 25, 2021

Conversation

jakub-gonet
Copy link
Member

@jakub-gonet jakub-gonet commented Feb 24, 2021

Description

Expo is moving away from using the .expo extension to identify "managed" apps in SDK 41.

Expo uses Root View that inherits from RNGH's RNGestureHandlerEnabledRootView so it's correctly picked up when initializing root helper. When used with gestureHandlerRootHOC it registers earlier as root view so it should work as well.

PR introducing this file for context: #925

Test plan

We tested the below code in the Expo setup:

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,
  },
  rectButton: {
    flex: 1,
    height: 60,
    padding: 10,
    justifyContent: 'space-between',
    alignItems: 'center',
    flexDirection: 'row',
  },
});

export default App;

Co-authored-by: Tomasz Sapeta <tsapeta@users.noreply.github.com>
@jakub-gonet jakub-gonet self-assigned this Feb 24, 2021
@brentvatne
Copy link
Collaborator

thanks 🙏

@jakub-gonet jakub-gonet merged commit 3456b38 into master Feb 25, 2021
@jakub-gonet jakub-gonet deleted the @kuba/remove-expo-specific-file branch February 25, 2021 10:18
braincore pushed a commit to braincore/react-native-gesture-handler that referenced this pull request Mar 4, 2021
Co-authored-by: Tomasz Sapeta <tsapeta@users.noreply.github.com>
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.

None yet

4 participants