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

Patch to display markdown with clickable links within a modal #54

Open
lukewlms opened this issue Feb 22, 2021 · 0 comments
Open

Patch to display markdown with clickable links within a modal #54

lukewlms opened this issue Feb 22, 2021 · 0 comments

Comments

@lukewlms
Copy link

Recently certain TouchableOpacity components are not clickable within modals. In our experience, Android and iOS need to use different imports - one from react-native and one from react-native-gesture-handler.

I didn't want to switch away from this lib so I created a simple patch to inject a custom TouchableOpacity component. Posting here in case it's useful to anyone else.

renders.js changes:

// ...
  // Link component:
  link: (node: LinkNode, output: OutputFunction, state: RenderState, styles: RenderStyles) => {
    const onPress = state.onLinkPress
    ///// Patch starts here: switch to TouchableOpacity from react-native-gesture-handler if needed
    return <styles.TouchableOpacity.Component key={state.key} onPress={onPress ? () => onPress(node.target) : null}><Text  style={[styles.link, {bottom:-4}]} >
      {typeof node.content === 'string' ? node.content : output(node.content, state)}
    </Text></styles.TouchableOpacity.Component>
    ///// PATCH ENDS HERE
  },

Setting markdown styles in our code:

    link: { color: theme.clickableLinkColor, fontSize: HELP_FONT_SIZE },
    // Inject element that can be clicked in a modal
    TouchableOpacity: { Component: isIOS
  ? TouchableOpacityRngh // from react-native-gesture-handler
  : TouchableOpacityRN;  // from RN
 },
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

No branches or pull requests

1 participant