|
1 | | -import { StyleSheet } from 'react-native'; |
| 1 | +import { StyleSheet, type ViewStyle } from 'react-native'; |
2 | 2 |
|
3 | 3 | import color from 'color'; |
4 | 4 |
|
5 | 5 | import { black, white } from '../../styles/themes/v2/colors'; |
6 | 6 | import type { InternalTheme } from '../../types'; |
| 7 | +import { splitStyles } from '../../utils/splitStyles'; |
7 | 8 |
|
8 | 9 | export type ButtonMode = |
9 | 10 | | 'text' |
@@ -230,3 +231,42 @@ export const getButtonColors = ({ |
230 | 231 | borderWidth, |
231 | 232 | }; |
232 | 233 | }; |
| 234 | + |
| 235 | +type ViewStyleBorderRadiusStyles = Partial< |
| 236 | + Pick< |
| 237 | + ViewStyle, |
| 238 | + | 'borderBottomEndRadius' |
| 239 | + | 'borderBottomLeftRadius' |
| 240 | + | 'borderBottomRightRadius' |
| 241 | + | 'borderBottomStartRadius' |
| 242 | + | 'borderTopEndRadius' |
| 243 | + | 'borderTopLeftRadius' |
| 244 | + | 'borderTopRightRadius' |
| 245 | + | 'borderTopStartRadius' |
| 246 | + | 'borderRadius' |
| 247 | + > |
| 248 | +>; |
| 249 | +export const getButtonTouchableRippleStyle = ( |
| 250 | + style?: ViewStyle, |
| 251 | + borderWidth: number = 0 |
| 252 | +): ViewStyleBorderRadiusStyles => { |
| 253 | + if (!style) return {}; |
| 254 | + const touchableRippleStyle: ViewStyleBorderRadiusStyles = {}; |
| 255 | + |
| 256 | + const [, borderRadiusStyles] = splitStyles( |
| 257 | + style, |
| 258 | + (style) => style.startsWith('border') && style.endsWith('Radius') |
| 259 | + ); |
| 260 | + |
| 261 | + ( |
| 262 | + Object.keys(borderRadiusStyles) as Array<keyof ViewStyleBorderRadiusStyles> |
| 263 | + ).forEach((key) => { |
| 264 | + const value = style[key as keyof ViewStyleBorderRadiusStyles]; |
| 265 | + if (typeof value === 'number') { |
| 266 | + // Only subtract borderWidth if value is greater than 0 |
| 267 | + const radius = value > 0 ? value - borderWidth : 0; |
| 268 | + touchableRippleStyle[key as keyof ViewStyleBorderRadiusStyles] = radius; |
| 269 | + } |
| 270 | + }); |
| 271 | + return touchableRippleStyle; |
| 272 | +}; |
0 commit comments