diff --git a/src/components/Appbar/AppbarContent.tsx b/src/components/Appbar/AppbarContent.tsx index 92fae42e7d..890f9fd581 100644 --- a/src/components/Appbar/AppbarContent.tsx +++ b/src/components/Appbar/AppbarContent.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { StyleSheet, Pressable, View } from 'react-native'; import type { + ColorValue, GestureResponderEvent, LayoutChangeEvent, StyleProp, @@ -54,7 +55,7 @@ export type Props = Omit, 'children'> & { /** * Custom color for the text. */ - color?: string; + color?: ColorValue; /** * Specifies the largest possible scale a title font can reach. */ diff --git a/src/components/Checkbox/CheckboxItem.tsx b/src/components/Checkbox/CheckboxItem.tsx index 3dabdd2de9..ffd1a7668e 100644 --- a/src/components/Checkbox/CheckboxItem.tsx +++ b/src/components/Checkbox/CheckboxItem.tsx @@ -1,5 +1,6 @@ import { StyleSheet, View } from 'react-native'; import type { + ColorValue, GestureResponderEvent, PressableAndroidRippleConfig, StyleProp, @@ -51,11 +52,11 @@ export type Props = { /** * Custom color for unchecked checkbox. */ - uncheckedColor?: string; + uncheckedColor?: ColorValue; /** * Custom color for checkbox. */ - color?: string; + color?: ColorValue; /** * Additional styles for container View. */ diff --git a/src/components/NavigationBar/NavigationBar.tsx b/src/components/NavigationBar/NavigationBar.tsx index bb91cdf92d..7509625d2d 100644 --- a/src/components/NavigationBar/NavigationBar.tsx +++ b/src/components/NavigationBar/NavigationBar.tsx @@ -192,11 +192,11 @@ export type Props = { /** * Custom color for icon and label in the active tab. */ - activeColor?: string; + activeColor?: ColorValue; /** * Custom color for icon and label in the inactive tab. */ - inactiveColor?: string; + inactiveColor?: ColorValue; /** * Whether the navigation bar is hidden when keyboard is shown. * On Android, this works best when [`windowSoftInputMode`](https://developer.android.com/guide/topics/manifest/activity-element#wsoft) is set to `adjustResize`. @@ -273,8 +273,8 @@ type ItemProps = { variant: 'stacked' | 'horizontal'; activeTintColor: ColorValue; inactiveTintColor: ColorValue; - activeColor?: string; - inactiveColor?: string; + activeColor?: ColorValue; + inactiveColor?: ColorValue; renderIcon?: Props['renderIcon']; renderLabel?: Props['renderLabel']; renderTouchable: NonNullable['renderTouchable']>; diff --git a/src/components/ProgressBar.tsx b/src/components/ProgressBar.tsx index 988f7981ee..d122966e9e 100644 --- a/src/components/ProgressBar.tsx +++ b/src/components/ProgressBar.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; // eslint-disable-next-line no-restricted-imports -- TODO: migrate ProgressBar to Reanimated. import { Animated, Platform, StyleSheet, View } from 'react-native'; import type { + ColorValue, LayoutChangeEvent, StyleProp, ViewProps, @@ -27,7 +28,7 @@ export type Props = ViewProps & { /** * Color of the progress bar. The track behind it stays `theme.colors.surfaceVariant`, whatever `color` is; pass `backgroundColor` in `style` to change it. */ - color?: string; + color?: ColorValue; /** * If the progress bar will show indeterminate progress. */ diff --git a/src/components/RadioButton/RadioButton.tsx b/src/components/RadioButton/RadioButton.tsx index 2ef02578f1..476f51a69c 100644 --- a/src/components/RadioButton/RadioButton.tsx +++ b/src/components/RadioButton/RadioButton.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { Platform, StyleSheet, View } from 'react-native'; import type { + ColorValue, GestureResponderEvent, MouseEvent, NativeSyntheticEvent, @@ -56,11 +57,11 @@ export type Props = Omit< /** * Custom color for unchecked radio. */ - uncheckedColor?: string; + uncheckedColor?: ColorValue; /** * Custom color for radio. */ - color?: string; + color?: ColorValue; /** * Whether the radio button is in an error state. When true, the ring * (unchecked) and dot (selected) use `theme.colors.error`. `disabled` diff --git a/src/components/RadioButton/RadioButtonItem.tsx b/src/components/RadioButton/RadioButtonItem.tsx index f5e81ca065..7c42fa6cce 100644 --- a/src/components/RadioButton/RadioButtonItem.tsx +++ b/src/components/RadioButton/RadioButtonItem.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { StyleSheet, View } from 'react-native'; import type { + ColorValue, GestureResponderEvent, PressableAndroidRippleConfig, StyleProp, @@ -55,11 +56,11 @@ export type Props = { /** * Custom color for unchecked radio. */ - uncheckedColor?: string; + uncheckedColor?: ColorValue; /** * Custom color for radio. */ - color?: string; + color?: ColorValue; /** * Status of radio button. */ diff --git a/src/components/SegmentedButtons/SegmentedButtonItem.tsx b/src/components/SegmentedButtons/SegmentedButtonItem.tsx index 4663cfb791..d37cebcb88 100644 --- a/src/components/SegmentedButtons/SegmentedButtonItem.tsx +++ b/src/components/SegmentedButtons/SegmentedButtonItem.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { StyleSheet, View } from 'react-native'; import type { + ColorValue, GestureResponderEvent, PressableAndroidRippleConfig, StyleProp, @@ -44,12 +45,12 @@ export type Props = { * @supported Available in v5.x with theme version 3 * Custom color for unchecked Text and Icon. */ - uncheckedColor?: string; + uncheckedColor?: ColorValue; /** * @supported Available in v5.x with theme version 3 * Custom color for checked Text and Icon. */ - checkedColor?: string; + checkedColor?: ColorValue; /** * Whether the button is disabled. */ diff --git a/src/components/SegmentedButtons/SegmentedButtons.tsx b/src/components/SegmentedButtons/SegmentedButtons.tsx index 486c8f1009..14f1b6091a 100644 --- a/src/components/SegmentedButtons/SegmentedButtons.tsx +++ b/src/components/SegmentedButtons/SegmentedButtons.tsx @@ -1,5 +1,6 @@ import { StyleSheet, View } from 'react-native'; import type { + ColorValue, GestureResponderEvent, StyleProp, TextStyle, @@ -63,8 +64,8 @@ export type Props = { icon?: IconSource; disabled?: boolean; 'aria-label'?: string; - checkedColor?: string; - uncheckedColor?: string; + checkedColor?: ColorValue; + uncheckedColor?: ColorValue; onPress?: (event: GestureResponderEvent) => void; label?: string; showSelectedCheck?: boolean; diff --git a/src/components/SegmentedButtons/utils.ts b/src/components/SegmentedButtons/utils.ts index ff17bf510a..8af07a24fe 100644 --- a/src/components/SegmentedButtons/utils.ts +++ b/src/components/SegmentedButtons/utils.ts @@ -12,8 +12,8 @@ type BaseProps = { }; type SegmentedButtonProps = { - checkedColor?: string; - uncheckedColor?: string; + checkedColor?: ColorValue; + uncheckedColor?: ColorValue; } & BaseProps; const DEFAULT_PADDING = 9; diff --git a/src/components/TouchableRipple/TouchableRipple.native.tsx b/src/components/TouchableRipple/TouchableRipple.native.tsx index 331386499c..665d9ef0e4 100644 --- a/src/components/TouchableRipple/TouchableRipple.native.tsx +++ b/src/components/TouchableRipple/TouchableRipple.native.tsx @@ -43,7 +43,7 @@ export type Props = PressableProps & { onPressIn?: (e: GestureResponderEvent) => void; onPressOut?: (e: GestureResponderEvent) => void; rippleColor?: ColorValue; - underlayColor?: string; + underlayColor?: ColorValue; ref?: React.Ref>; theme?: ThemeProp; }; diff --git a/src/components/TouchableRipple/TouchableRipple.tsx b/src/components/TouchableRipple/TouchableRipple.tsx index 7d3bb65613..11a606e68c 100644 --- a/src/components/TouchableRipple/TouchableRipple.tsx +++ b/src/components/TouchableRipple/TouchableRipple.tsx @@ -98,7 +98,7 @@ export type Props = PressableProps & { /** * Color of the underlay for the highlight effect (Android < 5.0 and iOS). */ - underlayColor?: string; + underlayColor?: ColorValue; /** * Content of the `TouchableRipple`: any React node, including several * children, fragments and `null`. Can be a function that receives the diff --git a/src/components/TouchableRipple/utils.ts b/src/components/TouchableRipple/utils.ts index 67a32335eb..f932235f1c 100644 --- a/src/components/TouchableRipple/utils.ts +++ b/src/components/TouchableRipple/utils.ts @@ -18,7 +18,7 @@ const getUnderlayColor = ({ underlayColor, }: { calculatedRippleColor: ColorValue; - underlayColor?: string; + underlayColor?: ColorValue; }) => { if (underlayColor != null) { return underlayColor; @@ -48,7 +48,7 @@ export const getTouchableRippleColors = ({ }: { theme: InternalTheme; rippleColor?: ColorValue; - underlayColor?: string; + underlayColor?: ColorValue; }): { calculatedRippleColor: ColorValue; calculatedUnderlayColor: ColorValue; diff --git a/src/components/__tests__/ColorProps.test.tsx b/src/components/__tests__/ColorProps.test.tsx new file mode 100644 index 0000000000..387bad9755 --- /dev/null +++ b/src/components/__tests__/ColorProps.test.tsx @@ -0,0 +1,83 @@ +import * as React from 'react'; +import type { ColorValue } from 'react-native'; + +import { expect, it } from '@jest/globals'; + +import { + Appbar, + Avatar, + Checkbox, + NavigationBar, + ProgressBar, + RadioButton, + SegmentedButtons, + TouchableRipple, +} from '../../index'; +import { render } from '../../test-utils'; + +it('color props accept ColorValue across components (#5179)', async () => { + const sampleColor: ColorValue = '#123456'; + + await render(); + await render(); + await render(); + await render(); + await render( + + + + ); + await render( + null} + onTabPress={() => {}} + activeColor={sampleColor} + inactiveColor={sampleColor} + /> + ); + await render( + {}} + buttons={[ + { + value: '1', + label: 'One', + checkedColor: sampleColor, + uncheckedColor: sampleColor, + }, + ]} + /> + ); + await render( + + ); + await render( + + ); + await render( + + ); + + expect(true).toBe(true); +});