alantoa / universal-tooltip

A universal Tooltip component for React Native and Web, powered by expo-modules.
162 stars 6 forks source link

Improve iOS UX - align for consistency with Android #12

Open fobos531 opened 11 months ago

fobos531 commented 11 months ago

Hello,

I've noticed that when I tap on the Trigger of the tooltip on iOS, the tooltip dismisses, but immediately presents again (since I tapped on the Trigger) - to illustrate what I'm talking about:

https://github.com/alantoa/universal-tooltip/assets/19533289/a35b6032-a4c0-4ba8-81b5-9903b84fdada

For comparison, on Android, when I do the same on Android, the tooltip is only dismissed, instead of being presented again. See video:

https://github.com/alantoa/universal-tooltip/assets/19533289/e05febb9-878f-4959-bb09-b87cb179437f

I find Android's behavior to be much more in-line with what the average user would expect. I compared this behavior with the upstream library used for iOS which is Popovers. The author has a reference app called "Find" (getfind.app) where they're utilizing Popovers in various places. The behavior there is exactly like on Android, i.e. tapping on the Trigger only dismisses the tooltip, instead of re-presenting them.

I suspect the "culprit" of this behavior lies somewhere in this method:

  override func didUpdateReactSubviews() {
    let firstView = self.reactSubviews()[0] as! RCTView
    contentView = firstView
    for index in 1..<self.reactSubviews().count {
      let subView = self.reactSubviews()[index]
      self.addSubview(subView)
    }
  }

Can this be aligned so that the iOS behavior is the same as Android?

For reference, this is the code from my videos

<Tooltip.Root
            {...Platform.select({
              default: {
                open,
                onDismiss: () => {
                  setOpen(false);
                },
              },
            })}>
            <Tooltip.Trigger>
              <Pressable
                {...Platform.select({
                  default: {
                    onPress: () => {
                      if (!open) {
                        setOpen(!open);
                      }
                    },
                  },
                })}>
                <Text weight="medium">Test tooltip text</Text>
              </Pressable>
            </Tooltip.Trigger>
            <Tooltip.Content
              containerStyle={{
                paddingLeft: 10,
                paddingRight: 10,
                paddingTop: 8,
                paddingBottom: 8,
              }}
              onTap={() => {
                setOpen(false);
              }}
              dismissDuration={300}
              disableTapToDismiss
              side="top"
              presetAnimation="fadeIn"
              backgroundColor={theme.colors.text}
              borderRadius={12}>
              <Tooltip.Text text="Test" style={{ color: theme.colors.mainBackground, fontSize: 16 }} />
            </Tooltip.Content>
          </Tooltip.Root>
alantoa commented 10 months ago

@fobos531 Hey, unfortunately, this is the default behavior of Popover. You can see here that some hack work needs to be done to make it work properly.