-
Notifications
You must be signed in to change notification settings - Fork 382
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
lareinayanyu
committed
Oct 17, 2024
1 parent
78a6514
commit 1482211
Showing
4 changed files
with
120 additions
and
14 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/webpack-plugin/lib/runtime/components/react/common.tsx
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,31 @@ | ||
import { TextStyle } from 'react-native' | ||
import { Children, cloneElement } from 'react' | ||
import { VarContext } from './context' | ||
import { isText } from './utils' | ||
|
||
export interface WrapChildrenConfig { | ||
hasVarDec: boolean | ||
varContext?: Record<string, any> | ||
} | ||
|
||
interface TextConfig { | ||
textStyle?: TextStyle | ||
textProps?: Record<string, any> | ||
} | ||
|
||
export function wrapChildren (props: Record<string, any> = {}, { hasVarDec, varContext }: WrapChildrenConfig, { textStyle, textProps } : TextConfig = {}) { | ||
let { children } = props | ||
if (textStyle || textProps) { | ||
children = Children.map(children, (child) => { | ||
if (isText(child)) { | ||
const style = { ...textStyle, ...child.props.style } | ||
return cloneElement(child, { ...textProps, style }) | ||
} | ||
return child | ||
}) | ||
} | ||
if (hasVarDec && varContext) { | ||
children = <VarContext.Provider value={varContext}>{children}</VarContext.Provider> | ||
} | ||
return children | ||
} |
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