react-native-autolink icon indicating copy to clipboard operation
react-native-autolink copied to clipboard

truncate only in urls

Open rerererarara opened this issue 1 year ago • 1 comments

Hi,

I want to use truncate only in urls. When I use truncate, Custom Matchers are also affected. How can I disable truncate in Custom Matchers?

For example like this;

    <Autolink
        text={text}
        url
        truncate={32}
        matchers={[
            {
                pattern: /@\[([^[]*)]\(([^(^)]*)\)/g,
                truncate:{0},
                style: { color: '#ff00ff' },
                getLinkText: (replacerArgs) => `@${replacerArgs[1]}`,
                onPress: (match) => {
                    navigate('userProfile', { userId: match.getReplacerArgs()[2] });
                },
            },
        ]}
    />

Thanks.

rerererarara avatar Sep 01 '22 21:09 rerererarara

The best way of achieving this at the moment would be to use a custom renderLink function. It receives the match as an argument, allowing you to perform custom rendering based on the match type.

Unfortunately, the truncate option is a "global" option designed to ensure no links are longer than X so there's no way of enabling/disabling it only for specific types at the moment. This behavior could definitely be improved, though it's not something I've ever run into. I'll leave this open and see if there's demand.

joshswan avatar Sep 02 '22 17:09 joshswan