-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add TextShadow component, add env var to silence design system emoji warnings * Temporarily default to disabling Android text shadows
- Loading branch information
1 parent
fc0ff05
commit 208856b
Showing
6 changed files
with
77 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { ReactElement, useMemo } from 'react'; | ||
import { StyleProp, TextStyle, View, ViewStyle } from 'react-native'; | ||
import { IS_ANDROID } from '@/env'; | ||
import { opacity } from '@/__swaps__/utils/swaps'; | ||
import { useColorMode } from '../../color/ColorMode'; | ||
import { useForegroundColor } from '../../color/useForegroundColor'; | ||
import { Text, TextProps } from '../Text/Text'; | ||
|
||
export interface TextShadowProps { | ||
blur?: number; | ||
children: ReactElement<TextProps>; | ||
color?: string; | ||
containerStyle?: StyleProp<ViewStyle>; | ||
disabled?: boolean; | ||
enableInLightMode?: boolean; | ||
shadowOpacity?: number; | ||
textStyle?: StyleProp<TextStyle>; | ||
x?: number; | ||
y?: number; | ||
} | ||
|
||
export const TextShadow = ({ | ||
blur = 16, | ||
children, | ||
color, | ||
containerStyle, | ||
// ⚠️ TODO: Need to test on Android - defaulting to disabled on Android for now | ||
disabled = IS_ANDROID, | ||
enableInLightMode, | ||
shadowOpacity = 0.6, | ||
textStyle, | ||
x = 0, | ||
y = 0, | ||
}: TextShadowProps) => { | ||
const { isDarkMode } = useColorMode(); | ||
|
||
const inferredTextColor = useForegroundColor(children.props.color ?? 'label'); | ||
const inferredTextSize = children.props.size || '17pt'; | ||
|
||
const [internalContainerStyle, internalTextStyle] = useMemo(() => { | ||
const extraSpaceForShadow = blur + Math.max(Math.abs(x), Math.abs(y)); | ||
return [ | ||
{ margin: -extraSpaceForShadow }, | ||
{ | ||
textShadowColor: opacity(color || inferredTextColor, shadowOpacity), | ||
textShadowOffset: { width: x, height: y }, | ||
textShadowRadius: blur, | ||
padding: extraSpaceForShadow, | ||
}, | ||
]; | ||
}, [blur, color, inferredTextColor, shadowOpacity, x, y]); | ||
|
||
return !disabled && (isDarkMode || enableInLightMode) ? ( | ||
<View style={[containerStyle, internalContainerStyle]}> | ||
<Text color={{ custom: 'transparent' }} size={inferredTextSize} style={[textStyle, internalTextStyle]} weight="bold"> | ||
{children} | ||
</Text> | ||
</View> | ||
) : ( | ||
<>{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