-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Izet Molla
authored and
Izet Molla
committed
Aug 5, 2023
1 parent
e4823c2
commit 629bdb0
Showing
6 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React, { FC, memo } from 'react'; | ||
import ParsedTextComp from 'react-native-parsed-text'; | ||
|
||
import { usePropsResolution } from '../../hooks/usePropsResolution'; | ||
import { ParsedTextProps } from './types'; | ||
|
||
const ParsedText: FC<ParsedTextProps> = ({ children, ...props }) => { | ||
const { ...resolvedProps } = usePropsResolution('Text', props); | ||
|
||
return <ParsedTextComp {...resolvedProps}>{children}</ParsedTextComp>; | ||
}; | ||
|
||
export default memo(ParsedText); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { PseudoComponentProps } from '../../contexts/theme'; | ||
|
||
import { TextProps } from 'react-native'; | ||
|
||
interface BaseParseShape | ||
extends Pick<TextProps, Exclude<keyof TextProps, 'onPress' | 'onLongPress'>> { | ||
/** arbitrary function to rewrite the matched string into something else */ | ||
renderText?: (matchingString: string, matches: string[]) => string; | ||
onPress?: (text: string, index: number) => void; | ||
onLongPress?: (text: string, index: number) => void; | ||
} | ||
|
||
/** | ||
* This is for built-in-patterns already supported by this library | ||
*/ | ||
interface DefaultParseShape extends BaseParseShape { | ||
type: 'url' | 'phone' | 'email'; | ||
} | ||
/** | ||
* If you want to provide a custom regexp, this is the configuration to use. | ||
* -- For historical reasons, all regexps are processed as if they have the global flag set. | ||
* -- Use the nonExhaustiveModeMaxMatchCount property to match a limited number of matches. | ||
*/ | ||
interface CustomParseShape extends BaseParseShape { | ||
pattern: string | RegExp; | ||
/** | ||
* Enables "non-exhaustive mode", where you can limit how many matches are found. | ||
* | ||
* If you want to match at most N things per-call to parse(), provide a positive number here. | ||
*/ | ||
nonExhaustiveModeMaxMatchCount?: number; | ||
} | ||
|
||
type ParseShape = DefaultParseShape | CustomParseShape; | ||
|
||
export interface ParsedTextProps | ||
extends TextProps, | ||
PseudoComponentProps<TextProps['style']> { | ||
parse?: ParseShape[]; | ||
childrenProps?: TextProps; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters