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

Add Text component #3202

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Add Text component #3202

wants to merge 9 commits into from

Conversation

m-bert
Copy link
Contributor

@m-bert m-bert commented Nov 8, 2024

Description

This PR adds Text component to Gesture Handler.

Upon investigating #3159 we decided that it will be better to add our own Text component, instead of forcing users to create their own version of Text with NativeViewGestureHandler.

Test plan

Tested on the following code:
import { useState } from 'react';
import {
  Text,
  GestureHandlerRootView,
  TouchableOpacity,
} from 'react-native-gesture-handler';

export default function App() {
  const [counter, setCounter] = useState(0);

  return (
    <GestureHandlerRootView
      style={{
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
      }}>
      <Text style={{ fontSize: 30 }}>{`Counter: ${counter}`}</Text>

      <TouchableOpacity
        onPress={() => {
          console.log('Touchable');
          setCounter(counter + 1);
        }}>
        <Text
          style={{ fontSize: 30 }}
          onPress={(e) => {
            console.log('Text', e.nativeEvent);
            setCounter(counter + 1);
          }}>
          {'Inner Text'}
        </Text>
      </TouchableOpacity>
    </GestureHandlerRootView>
  );
}

@@ -79,6 +86,7 @@ class NativeViewGestureHandler : GestureHandler<NativeViewGestureHandler>() {
is ReactEditText -> this.hook = EditTextHook(this, view)
is ReactSwipeRefreshLayout -> this.hook = SwipeRefreshLayoutHook(this, view)
is ReactScrollView -> this.hook = ScrollViewHook()
is ReactTextView -> this.hook = TextHook()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
is ReactTextView -> this.hook = TextHook()
is ReactTextView -> this.hook = TextViewHook()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't like it either 😅

Changed in 1852e67

Copy link
Member

Choose a reason for hiding this comment

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

You may have forgotten to commit this change or to push it 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like I did forgot to push it 😅 (5697078)

@@ -201,6 +214,10 @@ class NativeViewGestureHandler : GestureHandler<NativeViewGestureHandler>() {
fun shouldCancelRootViewGestureHandlerIfNecessary() = false
}

private class TextHook() : NativeViewGestureHandlerHook {
override fun shouldRecognizeSimultaneously(handler: GestureHandler<*>) = false
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this break in ScrollView?

Comment on lines +105 to +106
event.nativeEvent.oldState === State.ACTIVE &&
event.nativeEvent.state === State.END
Copy link
Member

Choose a reason for hiding this comment

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

Have you tried on iOS? Maybe checking simply the END state is enough?

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.

2 participants