Skip to content

Commit 7380d04

Browse files
committed
refactor: replace string with ColorValue for ThemeColors
1 parent 3b94e83 commit 7380d04

43 files changed

Lines changed: 282 additions & 187 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

example/src/DrawerItems.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import * as React from 'react';
2-
import { I18nManager, StyleSheet, View, Platform } from 'react-native';
2+
import {
3+
ColorValue,
4+
I18nManager,
5+
Platform,
6+
StyleSheet,
7+
View,
8+
} from 'react-native';
39

410
import { DrawerContentScrollView } from '@react-navigation/drawer';
511
import Constants, { ExecutionEnvironment } from 'expo-constants';
@@ -31,7 +37,7 @@ const DrawerItemsData = [
3137
label: 'Starred',
3238
icon: 'star',
3339
key: 1,
34-
right: ({ color }: { color: string }) => (
40+
right: ({ color }: { color: ColorValue }) => (
3541
<Badge
3642
visible
3743
size={8}

src/components/ActivityIndicator.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import {
33
Animated,
4+
ColorValue,
45
Easing,
56
Platform,
67
StyleProp,
@@ -20,7 +21,7 @@ export type Props = React.ComponentPropsWithRef<typeof View> & {
2021
/**
2122
* The color of the spinner.
2223
*/
23-
color?: string;
24+
color?: ColorValue;
2425
/**
2526
* Size of the indicator.
2627
*/

src/components/Appbar/AppbarAction.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import * as React from 'react';
2-
import type { Animated, StyleProp, View, ViewStyle } from 'react-native';
2+
import type {
3+
Animated,
4+
ColorValue,
5+
StyleProp,
6+
View,
7+
ViewStyle,
8+
} from 'react-native';
39

410
import { useInternalTheme } from '../../core/theming';
511
import type { Theme, ThemeProp } from '../../types';
@@ -11,7 +17,7 @@ export type Props = React.ComponentPropsWithoutRef<typeof IconButton> & {
1117
/**
1218
* Custom color for action icon.
1319
*/
14-
color?: string;
20+
color?: ColorValue;
1521
/**
1622
* Name of the icon to show.
1723
*/

src/components/Appbar/AppbarBackAction.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import type {
33
Animated,
4+
ColorValue,
45
GestureResponderEvent,
56
StyleProp,
67
View,
@@ -19,7 +20,7 @@ export type Props = $Omit<
1920
/**
2021
* Custom color for back icon.
2122
*/
22-
color?: string;
23+
color?: ColorValue;
2324
/**
2425
* Optional icon size.
2526
*/

src/components/Appbar/AppbarBackIcon.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import * as React from 'react';
2-
import { Image, Platform, StyleSheet, View } from 'react-native';
2+
import { ColorValue, Image, Platform, StyleSheet, View } from 'react-native';
33

44
import { useLocale } from '../../core/locale';
55
import MaterialCommunityIcon from '../MaterialCommunityIcon';
66

7-
const AppbarBackIcon = ({ size, color }: { size: number; color: string }) => {
7+
const AppbarBackIcon = ({
8+
size,
9+
color,
10+
}: {
11+
size: number;
12+
color: ColorValue;
13+
}) => {
814
const { direction } = useLocale();
915
const isRTL = direction === 'rtl';
1016
const iosIconSize = size - 3;

src/components/BottomNavigation/BottomNavigation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ export type Props<Route extends BaseRoute> = {
155155
renderIcon?: (props: {
156156
route: Route;
157157
focused: boolean;
158-
color: string;
158+
color: ColorValue;
159159
}) => React.ReactNode;
160160
/**
161161
* Callback which React Element to be used as tab label.
162162
*/
163163
renderLabel?: (props: {
164164
route: Route;
165165
focused: boolean;
166-
color: string;
166+
color: ColorValue;
167167
}) => React.ReactNode;
168168
/**
169169
* Callback which returns a React element to be used as the touchable for the tab item.

src/components/BottomNavigation/BottomNavigationBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ export type Props<Route extends BaseRoute> = {
122122
renderIcon?: (props: {
123123
route: Route;
124124
focused: boolean;
125-
color: string;
125+
color: ColorValue;
126126
}) => React.ReactNode;
127127
/**
128128
* Callback which React Element to be used as tab label.
129129
*/
130130
renderLabel?: (props: {
131131
route: Route;
132132
focused: boolean;
133-
color: string;
133+
color: ColorValue;
134134
}) => React.ReactNode;
135135
/**
136136
* Callback which returns a React element to be used as the touchable for the tab item.

src/components/BottomNavigation/utils.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import type { ColorValue } from 'react-native';
2+
13
import type { InternalTheme, Theme } from '../../types';
24

35
export const getActiveTintColor = ({
46
activeColor,
57
theme,
68
}: {
7-
activeColor: string | undefined;
9+
activeColor: ColorValue | undefined;
810
theme: InternalTheme;
911
}) => {
10-
if (typeof activeColor === 'string') {
12+
if (activeColor != null) {
1113
return activeColor;
1214
}
1315

@@ -18,10 +20,10 @@ export const getInactiveTintColor = ({
1820
inactiveColor,
1921
theme,
2022
}: {
21-
inactiveColor: string | undefined;
23+
inactiveColor: ColorValue | undefined;
2224
theme: InternalTheme;
2325
}) => {
24-
if (typeof inactiveColor === 'string') {
26+
if (inactiveColor != null) {
2527
return inactiveColor;
2628
}
2729

@@ -34,7 +36,7 @@ export const getLabelColor = ({
3436
focused,
3537
theme,
3638
}: {
37-
tintColor: string;
39+
tintColor: ColorValue;
3840
hasColor: boolean;
3941
focused: boolean;
4042
theme: InternalTheme;

src/components/Button/Button.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
import {
33
AccessibilityRole,
44
Animated,
5+
ColorValue,
56
GestureResponderEvent,
67
Platform,
78
PressableAndroidRippleConfig,
@@ -54,15 +55,15 @@ export type Props = $Omit<React.ComponentProps<typeof Surface>, 'mode'> & {
5455
* @deprecated Deprecated in v5.x - use `buttonColor` or `textColor` instead.
5556
* Custom text color for flat button, or background color for contained button.
5657
*/
57-
color?: string;
58+
color?: ColorValue;
5859
/**
5960
* Custom button's background color.
6061
*/
61-
buttonColor?: string;
62+
buttonColor?: ColorValue;
6263
/**
6364
* Custom button's text color.
6465
*/
65-
textColor?: string;
66+
textColor?: ColorValue;
6667
/**
6768
* Whether to show a loading indicator.
6869
*/

src/components/Button/utils.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ViewStyle } from 'react-native';
1+
import type { ColorValue, ViewStyle } from 'react-native';
22

33
import { black, white } from '../../theme/colors';
44
import { tokens } from '../../theme/tokens';
@@ -25,7 +25,7 @@ const isDark = ({
2525
backgroundColor,
2626
}: {
2727
dark?: boolean;
28-
backgroundColor?: string;
28+
backgroundColor?: ColorValue;
2929
}) => {
3030
if (typeof dark === 'boolean') {
3131
return dark;
@@ -44,7 +44,7 @@ const getButtonBackgroundColor = ({
4444
disabled,
4545
customButtonColor,
4646
}: BaseProps & {
47-
customButtonColor?: string;
47+
customButtonColor?: ColorValue;
4848
}) => {
4949
const { colors } = theme as Theme;
5050
if (customButtonColor && !disabled) {
@@ -81,8 +81,8 @@ const getButtonTextColor = ({
8181
backgroundColor,
8282
dark,
8383
}: BaseProps & {
84-
customTextColor?: string;
85-
backgroundColor: string;
84+
customTextColor?: ColorValue;
85+
backgroundColor: ColorValue;
8686
dark?: boolean;
8787
}) => {
8888
const { colors } = theme as Theme;
@@ -145,8 +145,8 @@ export const getButtonColors = ({
145145
}: {
146146
theme: InternalTheme;
147147
mode: ButtonMode;
148-
customButtonColor?: string;
149-
customTextColor?: string;
148+
customButtonColor?: ColorValue;
149+
customTextColor?: ColorValue;
150150
disabled?: boolean;
151151
dark?: boolean;
152152
}) => {

0 commit comments

Comments
 (0)