react-native-true-sheet icon indicating copy to clipboard operation
react-native-true-sheet copied to clipboard

Android New Architecture no press event

Open joaomirandamanie opened this issue 9 months ago • 56 comments

Before submitting a new issue

  • [x] I tested using the latest version of the library, as the bug might be already fixed.
  • [x] I tested using a supported version of react native.
  • [x] I checked for possible duplicate issues, with possible answers.

Bug summary

#154 I've updated to the latest version of the library since this bug is exactly the same one I'm getting, problem is, I'm using the same react native version and used the same example and I still don't get any press events on either buttons or pressables.

Library version

2.0.5

Environment info

react-native: 0.77.1 and tested with 0.76.7 as well newArch: true

Steps to reproduce

N/A

Reproducible example repository

N/A

joaomirandamanie avatar Mar 11 '25 11:03 joaomirandamanie

Opened a repro here: https://github.com/delphinebugner/repro-52 On Expo 52 x RN 0.76 New Arch! & edit: version 2.0.5 of the lib

How to use the repro

  1. Open the app on Android Real Device (not reproduced on simulator)
  2. Clic on "Open True Sheet" on home
  3. Sheet opens; click on "Count" button
  4. Count is not increased where it should

Image

delphinebugner avatar Mar 13 '25 15:03 delphinebugner

Update: probably linked to https://github.com/software-mansion/react-native-screens/issues/2219#issuecomment-2697125799

Using onPressIn makes it work, updating the repro :)

delphinebugner avatar Mar 13 '25 15:03 delphinebugner

@delphinebugner thanks. Not entirely linked but related. TrueSheet is kinda using similar implementation with RNScreens so whatever they will fix might help this as well.

I'll monitor that ticket :)

lodev09 avatar Mar 13 '25 16:03 lodev09

Use Pressable, RectButton or BorderlessButton exported by react-native-gesture-handler for now - don't use onPressIn. Here is my thread on it. https://x.com/hirbod_dev/status/1900204098344948015

hirbod avatar Mar 14 '25 11:03 hirbod

~~@hirbod just tried on my app and my repro: Pressable from react-native-gesture-handler do not work in TrueSheet 😞~~

~~Neither the onPress nor the onPressIn, keeping the RN Pressable + onPressIn solution now!~~ -> Edit: just forgot to add the GestureHandlerRootView, works now!

@lodev09 I pushed a RNGH example on the repro:

Image

delphinebugner avatar Mar 14 '25 13:03 delphinebugner

@delphinebugner Did you try RectButton instead? And did you follow the docs that your True Sheet Content needs to have its own GestureHandlerRootView?

hirbod avatar Mar 14 '25 13:03 hirbod

Not at all guilty -_-

delphinebugner avatar Mar 14 '25 13:03 delphinebugner

Adding the GestureHandlerRootView makes it work!

delphinebugner avatar Mar 14 '25 13:03 delphinebugner

You're welcome

hirbod avatar Mar 14 '25 13:03 hirbod

Thanks guys! I think it's safe to close this? 😅

lodev09 avatar Mar 15 '25 05:03 lodev09

I'd prefer to keep it opened, as it's only a workaround to use Pressable from Gesture Handler - would be great to have the default Pressable working, not just because I can't style the RNGH one with Native Wind 🥲

delphinebugner avatar Mar 16 '25 17:03 delphinebugner

Hey guys I'm also experiencing the same issue.

I'm using the Pressable from RNGH and I added the TrueSheet own GestureHandlerRootView as mentioned in the troubleshooting of the doc, and the Pressable still do not work...

Any other ideas on how I could fix this? 🥲

I'm on RN 0.76.7 and newArch enabled btw.

(the package is awesome btw thank you so much, it's been a blessing)

guillaumehcht avatar Mar 16 '25 20:03 guillaumehcht

Okay I'll keep this open for now but I doubt there's anything we could do on our end to fix this. It looked like this is a root issue from RN fabric itself :/

lodev09 avatar Mar 17 '25 03:03 lodev09

Just fyi I investigated this a bit further, the Pressable component from RNGH functions correctly within the TrueSheet for Android.

BUT it doesn't work when it is passed in the FooterComponent of the TrueSheet. Not sure why.

guillaumehcht avatar Mar 17 '25 12:03 guillaumehcht

@delphinebugner

I'd prefer to keep it opened, as it's only a workaround to use Pressable from Gesture Handler - would be great to have the default Pressable working, not just because I can't style the RNGH one with Native Wind 🥲

actually... you can

hirbod avatar Mar 17 '25 23:03 hirbod

@hirbod which interop do you use? Especially interested with the active: transformers that did not work out of the bow when I tried

delphinebugner avatar Mar 18 '25 08:03 delphinebugner

@lodev09 and the rest https://github.com/software-mansion/react-native-screens/pull/2788

hirbod avatar Mar 18 '25 13:03 hirbod

I solve it wrapping the bottom sheet content with GestureHandlerRootView and using Pressable from gesture handler.

nicolascavallin avatar Mar 31 '25 06:03 nicolascavallin

@hirbod which interop do you use? Especially interested with the active: transformers that did not work out of the bow when I tried

@delphinebugner Hello i am facing the same issue, did you manage how to use active: transformers with nativewind and RNGH Pressable ? Thanks

iCodePup avatar Apr 22 '25 12:04 iCodePup

@iCodePup no, we used a temporary workaround by having two pressable nested: one for the onPress action on Android, one for the style:

interface Props {
  onPress?: () => void;
  onLongPress?: () => void;
}

/**
 * RN Pressable does not work on Android x Sheets in New Arch on True Sheet.
 * We use this wrapper to have Gesture Handler Pressable instead (it works), waiting for the fix.
 * It requires to duplicate all "onPress" declarations but it's better than using RNGH Pressable everywhere
 * that does not support NativeWind styles out of the box (especially the :active ones) (+ has a different typing).
 *
 * Remove this when https://github.com/lodev09/react-native-true-sheet/issues/163 (+ probable React Native behind) is fixed.
 */
export const TrueSheetPressableWrapper = ({
  onPress,
  onLongPress,
  children,
}: PropsWithChildren<Props>) => {
  const longPress = Gesture.LongPress()
    .onEnd(() => onLongPress?.())
    .runOnJS(true);
  const tap = Gesture.Tap()
    .onEnd(() => onPress?.())
    .runOnJS(true);
  const gesture = Gesture.Exclusive(longPress, tap);
  
  // No need for a hack on iOS!
  if (Platform.OS === "ios") {
    return children;
  }

  return <GestureDetector gesture={gesture}>{children}</GestureDetector>;
};

We used it like this:

          <TrueSheetPressableWrapper onPress={handlePress}>
              <CustomButton
                onPress={handlePress}
                className="bg-red active:bg-blue"
              />
          </TrueSheetPressableWrapper>

But we decided this week to roll back and remove react-native-true-sheet from our project. We use Gorrhom's sheet back, partially because of this issue.

Maybe we'll come back to it later 🙂

delphinebugner avatar Apr 22 '25 12:04 delphinebugner

i spent some effort with the leads in https://github.com/software-mansion/react-native-screens/pull/2788:

true-sheet's js measure event will give a pageX of -9999. I searched this lib and found the left is set as -9999. I patch-packaged out lib/commonjs/TrueSheet.js's $nativeSheet's left and it seems like my physical phone can respond normally again. I havent got a chance to do rigorous testing yet.

ping @lodev09

lovegaoshi avatar May 08 '25 12:05 lovegaoshi

i spent some effort with the leads in software-mansion/react-native-screens#2788:

I'm going to try your patch and see... I've seen you also added dragging?

https://github.com/lodev09/react-native-true-sheet/compare/main...lovegaoshi:react-native-true-sheet:APM

telemakhos avatar May 08 '25 22:05 telemakhos

my fork is a personal fork with fixes relevant to me. you should refer only to what i posted above (left = -9999) for this ticket.

On Thu, May 8, 2025, 3:06 PM Telemakhos @.***> wrote:

telemakhos left a comment (lodev09/react-native-true-sheet#163) https://github.com/lodev09/react-native-true-sheet/issues/163#issuecomment-2864540412

i spent some effort with the leads in software-mansion/react-native-screens#2788 https://github.com/software-mansion/react-native-screens/pull/2788:

I'm going to try your patch and see... I've seen you also added dragging?

main...lovegaoshi:react-native-true-sheet:APM https://github.com/lodev09/react-native-true-sheet/compare/main...lovegaoshi:react-native-true-sheet:APM

— Reply to this email directly, view it on GitHub https://github.com/lodev09/react-native-true-sheet/issues/163#issuecomment-2864540412, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZMOVVSPE2EDJVGKK33BVM325PIOHAVCNFSM6AAAAABYYU53VGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQNRUGU2DANBRGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

lovegaoshi avatar May 08 '25 22:05 lovegaoshi

i spent some effort with the leads in software-mansion/react-native-screens#2788:

true-sheet's js measure event will give a pageX of -9999. I searched this lib and found the left is set as -9999. I patch-packaged out lib/commonjs/TrueSheet.js's $nativeSheet's left and it seems like my physical phone can respond normally again. I havent got a chance to do rigorous testing yet.

ping @lodev09

I tried this patch and it indeed fixed the issues I had. I am using pressables and inputs from Tamagui.

athusrv avatar May 23 '25 12:05 athusrv

im back to share another getcha - do NOT wrap your truesheet within a component that has another component in its parent affecting its layout, as it affects measureLayout's pageX (ie. truesheet's position: absolute is only relative to its direct parent, not the root component).

so say:

<Root>
  <Com1-with-some-height />
  <Com2>
      <TrueSheet />
  </Com2>
</Root>

truesheet's responderRegion will be off by Com1's height.

lovegaoshi avatar Jun 02 '25 18:06 lovegaoshi

im back to share another getcha - do NOT wrap your truesheet within a component that has another component in its parent affecting its layout, as it affects measureLayout's pageX (ie. truesheet's position: absolute is only relative to its direct parent, not the root component).

so say:

<Root>
  <Com1-with-some-height />
  <Com2>
      <TrueSheet />
  </Com2>
</Root>

truesheet's responderRegion will be off by Com1's height.

Does that fix the issue for you? The docs say "Define TrueSheet inside any component and attach a ref to it." so this must be unintended behavior if all <TrueSheet/> components need to be at the root

SpaceTsundere avatar Jun 02 '25 18:06 SpaceTsundere

see https://stackoverflow.com/questions/6867244/force-position-absolute-to-be-relative-to-the-document-and-not-the-parent-con for an explanation of position:absolute. it seems rather the newarch fixed the intended behavior of position:absolute and as a fullscreen component, any truesheet component SHOULD be put under root.

and u should instead use https://sheet.lodev09.com/guides/global-methods.

lovegaoshi avatar Jun 02 '25 19:06 lovegaoshi

see https://stackoverflow.com/questions/6867244/force-position-absolute-to-be-relative-to-the-document-and-not-the-parent-con for an explanation of position:absolute. it seems rather the newarch fixed the intended behavior of position:absolute and as a fullscreen component, any truesheet component SHOULD be put under root.

and u should instead use https://sheet.lodev09.com/guides/global-methods.

Oh nice, thanks for the quick reply! I'll have to give that a go 💜

Edit: Unfortunately moving to the root didn't work! Still stuck with the awful button migration fix

SpaceTsundere avatar Jun 02 '25 19:06 SpaceTsundere

the problem here is 2 folds. first trueSheet uses a left:-9999 that will NEVER work unless you patch it out. then if u do end up wrapping a sheet inside another compoenent, your responderRegion could then be affected by the neighboring components. pls read up

lovegaoshi avatar Jun 03 '25 03:06 lovegaoshi

unfortunately I need a truesheet component to actually inherit states from a parent component, moving ALL of them to the root component is no longer viable for me. My current workaround is to put a pressable right at the top of truesheet and useEffect calculate its dimensions via ref.measure, then offset the truesheet responder region by the measured pageX and pageY via spreading it into $nativeSheet. perhaps it's helpful to someone out there.

lovegaoshi avatar Jun 18 '25 19:06 lovegaoshi