Skip to content

Commit

Permalink
fix: resolve typescript and test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakeoon committed Feb 8, 2022
1 parent 4a5961f commit 3de8a10
Show file tree
Hide file tree
Showing 44 changed files with 279 additions and 165 deletions.
14 changes: 6 additions & 8 deletions example/src/Examples/ButtonExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { Button, List, useTheme } from 'react-native-paper';
import ScreenWrapper from '../ScreenWrapper';

const ButtonExample = () => {
const { colors } = useTheme();
const theme = useTheme();

const accentColor = theme.isV3 ? theme.colors.primary : theme.colors.accent;

return (
<ScreenWrapper>
Expand All @@ -13,11 +15,7 @@ const ButtonExample = () => {
<Button onPress={() => {}} style={styles.button}>
Default
</Button>
<Button
color={colors?.accent}
onPress={() => {}}
style={styles.button}
>
<Button color={accentColor} onPress={() => {}} style={styles.button}>
Custom
</Button>
<Button disabled onPress={() => {}} style={styles.button}>
Expand Down Expand Up @@ -46,7 +44,7 @@ const ButtonExample = () => {
</Button>
<Button
mode="outlined"
color={colors?.accent}
color={accentColor}
onPress={() => {}}
style={styles.button}
>
Expand Down Expand Up @@ -94,7 +92,7 @@ const ButtonExample = () => {
</Button>
<Button
mode="contained"
color={colors?.accent}
color={accentColor}
onPress={() => {}}
style={styles.button}
>
Expand Down
36 changes: 16 additions & 20 deletions example/src/Examples/TextExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ScreenWrapper from '../ScreenWrapper';

const SectionHeader = ({ children }: React.PropsWithChildren<{}>) => {
return (
<Text variant="title-large" style={styles.sectionHeader}>
<Text variant="titleLarge" style={styles.sectionHeader}>
{children}
</Text>
);
Expand All @@ -32,57 +32,53 @@ const TextExample = () => {

<SectionHeader>Text component:</SectionHeader>

<Text
style={styles.text}
variant="display-large"
theme={{ colors: { primary: '#fff' } }}
>
<Text style={styles.text} variant="displayLarge">
Display Large
</Text>
<Text style={styles.text} variant="display-medium">
<Text style={styles.text} variant="displayMedium">
Display Medium
</Text>
<Text style={styles.text} variant="display-small">
<Text style={styles.text} variant="displaySmall">
Display small
</Text>

<Text style={styles.text} variant="headline-large">
<Text style={styles.text} variant="headlineLarge">
Headline Large
</Text>
<Text style={styles.text} variant="headline-medium">
<Text style={styles.text} variant="headlineMedium">
Headline Medium
</Text>
<Text style={styles.text} variant="headline-small">
<Text style={styles.text} variant="headlineSmall">
Headline Small
</Text>

<Text style={styles.text} variant="title-large">
<Text style={styles.text} variant="titleLarge">
Title Large
</Text>
<Text style={styles.text} variant="title-medium">
<Text style={styles.text} variant="titleMedium">
Title Medium
</Text>
<Text style={styles.text} variant="title-small">
<Text style={styles.text} variant="titleSmall">
Title Small
</Text>

<Text style={styles.text} variant="body-large">
<Text style={styles.text} variant="bodyLarge">
Body Large
</Text>
<Text style={styles.text} variant="body-medium">
<Text style={styles.text} variant="bodyMedium">
Body Medium
</Text>
<Text style={styles.text} variant="body-small">
<Text style={styles.text} variant="bodySmall">
Body Small
</Text>

<Text style={styles.text} variant="label-large">
<Text style={styles.text} variant="labelLarge">
Label Large
</Text>
<Text style={styles.text} variant="label-medium">
<Text style={styles.text} variant="labelMedium">
Label Medium
</Text>
<Text style={styles.text} variant="label-small">
<Text style={styles.text} variant="labelSmall">
Label Small
</Text>
</View>
Expand Down
10 changes: 7 additions & 3 deletions example/src/Examples/TextInputExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const TextInputExample = () => {

const _isUsernameValid = (name: string) => /^[a-zA-Z]*$/.test(name);

const { colors } = useTheme();
const theme = useTheme();

const inputActionHandler = (type: keyof State, payload: string) =>
dispatch({
Expand All @@ -121,7 +121,11 @@ const TextInputExample = () => {

const newColors = {
...state.iconsColor,
[name]: !color ? colors?.accent : undefined,
[name]: !color
? theme.isV3
? theme.colors.primary
: theme.colors?.accent
: undefined,
};

dispatch({
Expand Down Expand Up @@ -230,7 +234,7 @@ const TextInputExample = () => {
right={
<TextInput.Icon
name="chevron-up"
color={(focused) => (focused ? colors?.primary : undefined)}
color={(focused) => (focused ? theme.colors?.primary : undefined)}
/>
}
/>
Expand Down
2 changes: 1 addition & 1 deletion example/src/ScreenWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function ScreenWrapper({
styles.container,
{
backgroundColor: isV3
? (getToken('md.sys.color.background') as string)
? (getToken?.('md.sys.color.background') as string)
: colors?.background,
paddingBottom: insets.bottom,
paddingLeft: insets.left,
Expand Down
8 changes: 6 additions & 2 deletions src/components/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ const Badge = ({
}).start();
}, [visible, opacity, scale]);

const { backgroundColor = theme.colors?.notification, ...restStyle } =
(StyleSheet.flatten(style) || {}) as TextStyle;
const {
backgroundColor = theme.isV3
? theme.colors.primary
: theme.colors?.notification,
...restStyle
} = (StyleSheet.flatten(style) || {}) as TextStyle;

const textColor = getContrastingColor(backgroundColor || white, white, black);

Expand Down
9 changes: 8 additions & 1 deletion src/components/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,14 @@ const Banner = ({
</View>
) : null}
<Text
style={[styles.message, { color: theme.colors?.text }]}
style={[
styles.message,
{
color: theme.isV3
? theme.colors.onSurface
: theme.colors.text,
},
]}
accessibilityLiveRegion={visible ? 'polite' : 'none'}
accessibilityRole="alert"
>
Expand Down
17 changes: 13 additions & 4 deletions src/components/Checkbox/CheckboxAndroid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,28 @@ const CheckboxAndroid = ({

const checked = status === 'checked';
const indeterminate = status === 'indeterminate';
const checkedColor = rest.color || theme?.colors?.accent;

const themeTextColor = theme.isV3
? theme.colors.onSurface
: theme.colors.text;
const themeDisabledColor = theme.isV3
? theme.colors.onSurfaceDisabled
: theme.colors.text;

const checkedColor =
rest.color || theme.isV3 ? theme.colors.primary : theme?.colors?.accent;
const uncheckedColor =
rest.uncheckedColor ||
color(theme?.colors?.text)
color(themeTextColor)
.alpha(theme.dark ? 0.7 : 0.54)
.rgb()
.string();

let rippleColor, checkboxColor;

if (disabled) {
rippleColor = color(theme?.colors?.text).alpha(0.16).rgb().string();
checkboxColor = theme?.colors?.disabled;
rippleColor = color(themeTextColor).alpha(0.16).rgb().string();
checkboxColor = themeDisabledColor;
} else {
rippleColor = color(checkedColor).fade(0.32).rgb().string();
checkboxColor = checked ? checkedColor : uncheckedColor;
Expand Down
19 changes: 15 additions & 4 deletions src/components/Checkbox/CheckboxIOS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,25 @@ const CheckboxIOS = ({
const checked = status === 'checked';
const indeterminate = status === 'indeterminate';

const checkedColor = disabled
? theme?.colors?.disabled
: rest.color || theme?.colors?.accent;
const disabledColor = theme.isV3
? theme.colors.onSurfaceDisabled
: theme?.colors?.disabled;

const defaultColor = theme.isV3
? theme.colors.primary
: theme?.colors?.accent;

const checkedColor = disabled ? disabledColor : rest.color || defaultColor;

let rippleColor;

if (disabled) {
rippleColor = color(theme?.colors?.text).alpha(0.16).rgb().string();
rippleColor = color(
theme.isV3 ? theme.colors.onSurface : theme?.colors?.text
)
.alpha(0.16)
.rgb()
.string();
} else {
rippleColor = color(checkedColor).fade(0.32).rgb().string();
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Checkbox/CheckboxItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const CheckboxItem = ({
style={[
styles.label,
{
color: theme.colors?.text,
color: theme.isV3 ? theme.colors.onSurface : theme.colors.text,
textAlign: isLeading ? 'right' : 'left',
},
labelStyle,
Expand Down
15 changes: 11 additions & 4 deletions src/components/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ const Chip = ({
const { backgroundColor = defaultBackgroundColor, borderRadius = 16 } =
(StyleSheet.flatten(style) || {}) as ViewStyle;

const themeTextColor = theme.isV3
? theme.colors.onSurface
: theme.colors.text;
const themeDisabledColor = theme.isV3
? theme.colors.onSurfaceDisabled
: theme.colors.text;

const borderColor =
mode === 'outlined'
? color(
Expand All @@ -184,14 +191,14 @@ const Chip = ({
.string()
: backgroundColor;
const textColor = disabled
? colors?.disabled
: color(selectedColor !== undefined ? selectedColor : colors?.text)
? themeDisabledColor
: color(selectedColor !== undefined ? selectedColor : themeTextColor)
.alpha(0.87)
.rgb()
.string();
const iconColor = disabled
? colors?.disabled
: color(selectedColor !== undefined ? selectedColor : colors?.text)
? themeDisabledColor
: color(selectedColor !== undefined ? selectedColor : themeTextColor)
.alpha(0.54)
.rgb()
.string();
Expand Down
19 changes: 13 additions & 6 deletions src/components/DataTable/DataTablePagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ const PaginationControls = ({
onPageChange,
showFastPaginationControls,
}: PaginationControlsProps) => {
const { colors } = useTheme();
const theme = useTheme();

const textColor = theme.isV3 ? theme.colors.onSurface : theme.colors.text;

return (
<>
Expand All @@ -95,7 +97,7 @@ const PaginationControls = ({
direction={I18nManager.isRTL ? 'rtl' : 'ltr'}
/>
)}
color={colors?.text}
color={textColor}
disabled={page === 0}
onPress={() => onPageChange(0)}
accessibilityLabel="page-first"
Expand All @@ -110,7 +112,7 @@ const PaginationControls = ({
direction={I18nManager.isRTL ? 'rtl' : 'ltr'}
/>
)}
color={colors?.text}
color={textColor}
disabled={page === 0}
onPress={() => onPageChange(page - 1)}
accessibilityLabel="chevron-left"
Expand All @@ -124,7 +126,7 @@ const PaginationControls = ({
direction={I18nManager.isRTL ? 'rtl' : 'ltr'}
/>
)}
color={colors?.text}
color={textColor}
disabled={numberOfPages === 0 || page === numberOfPages - 1}
onPress={() => onPageChange(page + 1)}
accessibilityLabel="chevron-right"
Expand All @@ -139,7 +141,7 @@ const PaginationControls = ({
direction={I18nManager.isRTL ? 'rtl' : 'ltr'}
/>
)}
color={colors?.text}
color={textColor}
disabled={numberOfPages === 0 || page === numberOfPages - 1}
onPress={() => onPageChange(numberOfPages - 1)}
accessibilityLabel="page-last"
Expand Down Expand Up @@ -270,7 +272,12 @@ const DataTablePagination = ({
selectPageDropdownAccessibilityLabel,
...rest
}: Props) => {
const labelColor = color(theme?.colors?.text).alpha(0.6).rgb().string();
const labelColor = color(
theme.isV3 ? theme.colors.onSurface : theme?.colors.text
)
.alpha(0.6)
.rgb()
.string();

return (
<View
Expand Down
8 changes: 5 additions & 3 deletions src/components/DataTable/DataTableTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ const DataTableTitle = ({
}).start();
}, [sortDirection, spinAnim]);

const textColor = color(theme?.colors?.text).alpha(0.6).rgb().string();
const textColor = theme.isV3 ? theme.colors.onSurface : theme?.colors?.text;

const alphaTextColor = color(textColor).alpha(0.6).rgb().string();

const spin = spinAnim.interpolate({
inputRange: [0, 1],
Expand All @@ -110,7 +112,7 @@ const DataTableTitle = ({
<MaterialCommunityIcon
name="arrow-up"
size={16}
color={theme?.colors?.text || black}
color={textColor || black}
direction={I18nManager.isRTL ? 'rtl' : 'ltr'}
/>
</Animated.View>
Expand All @@ -124,7 +126,7 @@ const DataTableTitle = ({
<Text
style={[
styles.cell,
sortDirection ? styles.sorted : { color: textColor },
sortDirection ? styles.sorted : { color: alphaTextColor },
]}
numberOfLines={numberOfLines}
>
Expand Down
Loading

0 comments on commit 3de8a10

Please sign in to comment.