Skip to content

Commit

Permalink
feat: adjust typography component, fix theme types (#3066)
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakeoon authored Feb 2, 2022
1 parent 01db18b commit f0be14c
Show file tree
Hide file tree
Showing 44 changed files with 824 additions and 333 deletions.
5 changes: 3 additions & 2 deletions example/src/Examples/RadioButtonGroupExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { RadioButton, Paragraph, List, useTheme } from 'react-native-paper';
import ScreenWrapper from '../ScreenWrapper';

const RadioButtonGroupExample = () => {
const [value, setValue] = React.useState<string>('first');
const [value2, setValue2] = React.useState<string>('first');
const [value, setValue] = React.useState('first');
const [value2, setValue2] = React.useState('first');

const { colors } = useTheme();

return (
<ScreenWrapper>
<List.Section title="With RadioButton">
Expand Down
84 changes: 77 additions & 7 deletions example/src/Examples/TextExample.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,99 @@
import * as React from 'react';
import { StyleSheet } from 'react-native';
import { StyleSheet, View } from 'react-native';
import {
Caption,
Headline,
Paragraph,
Subheading,
Text,
Title,
} from 'react-native-paper';
import ScreenWrapper from '../ScreenWrapper';

const SectionHeader = ({ children }: React.PropsWithChildren<{}>) => {
return (
<Text variant="title-large" style={styles.sectionHeader}>
{children}
</Text>
);
};

const TextExample = () => {
return (
<ScreenWrapper style={styles.container}>
<Caption style={styles.text}>Caption</Caption>
<Paragraph style={styles.text}>Paragraph</Paragraph>
<Subheading style={styles.text}>Subheading</Subheading>
<Title style={styles.text}>Title</Title>
<Headline style={styles.text}>Headline</Headline>
<ScreenWrapper>
<View style={styles.container}>
<SectionHeader>Old text components:</SectionHeader>

<Caption style={styles.text}>Caption</Caption>
<Paragraph style={styles.text}>Paragraph</Paragraph>
<Subheading style={styles.text}>Subheading</Subheading>
<Title style={styles.text}>Title</Title>
<Headline style={styles.text}>Headline</Headline>

<SectionHeader>Text component:</SectionHeader>

<Text style={styles.text} variant="display-large">
Display Large
</Text>
<Text style={styles.text} variant="display-medium">
Display Medium
</Text>
<Text style={styles.text} variant="display-small">
Display small
</Text>

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

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

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

<Text style={styles.text} variant="label-large">
Label Large
</Text>
<Text style={styles.text} variant="label-medium">
Label Medium
</Text>
<Text style={styles.text} variant="label-small">
Label Small
</Text>
</View>
</ScreenWrapper>
);
};

TextExample.title = 'Typography';

const styles = StyleSheet.create({
sectionHeader: {
marginTop: 16,
marginBottom: 8,
opacity: 0.6,
},
container: {
padding: 16,
},
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
? md('md.sys.color.background')
? (md('md.sys.color.background') as string)
: colors?.background,
paddingBottom: insets.bottom,
paddingLeft: insets.left,
Expand Down
47 changes: 5 additions & 42 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { createDrawerNavigator } from '@react-navigation/drawer';
import {
Provider as PaperProvider,
DarkTheme,
DefaultTheme,
Theme,
DefaultTheme as LightTheme,
ThemeBase,
} from 'react-native-paper';
import App from './RootNavigator';
import DrawerItems from './DrawerItems';
Expand All @@ -34,39 +34,6 @@ declare global {
const PERSISTENCE_KEY = 'NAVIGATION_STATE';
const PREFERENCES_KEY = 'APP_PREFERENCES';

const CustomDarkTheme = {
...DarkTheme,
colors: {
...DarkTheme.colors,
customColor: '#BADA55',
},
fonts: {
...DarkTheme.fonts,
superLight: { ...DarkTheme.fonts['light'] },
},
animation: {
...DarkTheme.animation,
customProperty: 1,
},
};

const CustomDefaultTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
customColor: '#BADA55',
},
fonts: {
...DefaultTheme.fonts,
superLight: { ...DefaultTheme.fonts['light'] },
},
userDefinedThemeProperty: '',
animation: {
...DefaultTheme.animation,
customProperty: 1,
},
};

export const PreferencesContext = React.createContext<any>(null);

const DrawerContent = () => {
Expand Down Expand Up @@ -94,7 +61,7 @@ export default function PaperExample() {
InitialState | undefined
>();

const [theme, setTheme] = React.useState<Theme>(CustomDefaultTheme);
const [theme, setTheme] = React.useState<ThemeBase>(LightTheme);
const [rtl, setRtl] = React.useState<boolean>(I18nManager.isRTL);

React.useEffect(() => {
Expand Down Expand Up @@ -124,9 +91,7 @@ export default function PaperExample() {

if (preferences) {
// eslint-disable-next-line react/no-did-mount-set-state
setTheme(
preferences.theme === 'dark' ? CustomDarkTheme : CustomDefaultTheme
);
setTheme(preferences.theme === 'dark' ? DarkTheme : LightTheme);

if (typeof preferences.rtl === 'boolean') {
setRtl(preferences.rtl);
Expand Down Expand Up @@ -166,9 +131,7 @@ export default function PaperExample() {
const preferences = React.useMemo(
() => ({
toggleTheme: () =>
setTheme((theme) =>
theme === CustomDefaultTheme ? CustomDarkTheme : CustomDefaultTheme
),
setTheme((theme) => (theme === LightTheme ? DarkTheme : LightTheme)),
toggleRtl: () => setRtl((rtl) => !rtl),
rtl,
theme,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Card/CardTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
} from 'react-native';

import { withTheme } from '../../core/theming';
import Caption from './../Typography/Caption';
import Title from './../Typography/Title';
import type { Theme } from '../../types';
import Caption from '../Typography/v2/Caption';
import Title from '../Typography/v2/Title';

type Props = React.ComponentPropsWithRef<typeof View> & {
/**
Expand Down
8 changes: 4 additions & 4 deletions src/components/Checkbox/CheckboxAndroid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ const CheckboxAndroid = ({

const checked = status === 'checked';
const indeterminate = status === 'indeterminate';
const checkedColor = rest.color || theme.colors?.accent;
const checkedColor = rest.color || theme?.colors?.accent;
const uncheckedColor =
rest.uncheckedColor ||
color(theme.colors?.text)
color(theme?.colors?.text)
.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(theme?.colors?.text).alpha(0.16).rgb().string();
checkboxColor = theme?.colors?.disabled;
} else {
rippleColor = color(checkedColor).fade(0.32).rgb().string();
checkboxColor = checked ? checkedColor : uncheckedColor;
Expand Down
6 changes: 3 additions & 3 deletions src/components/Checkbox/CheckboxIOS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ const CheckboxIOS = ({
const indeterminate = status === 'indeterminate';

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

let rippleColor;

if (disabled) {
rippleColor = color(theme.colors?.text).alpha(0.16).rgb().string();
rippleColor = color(theme?.colors?.text).alpha(0.16).rgb().string();
} else {
rippleColor = color(checkedColor).fade(0.32).rgb().string();
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/DataTable/DataTablePagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const PaginationControls = ({
showFastPaginationControls,
}: PaginationControlsProps) => {
const { colors } = useTheme();

return (
<>
{showFastPaginationControls ? (
Expand Down Expand Up @@ -269,7 +270,7 @@ const DataTablePagination = ({
selectPageDropdownAccessibilityLabel,
...rest
}: Props) => {
const labelColor = color(theme.colors?.text).alpha(0.6).rgb().string();
const labelColor = color(theme?.colors?.text).alpha(0.6).rgb().string();

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

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

const spin = spinAnim.interpolate({
inputRange: [0, 1],
Expand All @@ -110,7 +110,7 @@ const DataTableTitle = ({
<MaterialCommunityIcon
name="arrow-up"
size={16}
color={theme.colors?.text || black}
color={theme?.colors?.text || black}
direction={I18nManager.isRTL ? 'rtl' : 'ltr'}
/>
</Animated.View>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dialog/DialogTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { StyleSheet, StyleProp, TextStyle } from 'react-native';
import Title from '../Typography/Title';
import Title from '../Typography/v2/Title';
import { withTheme } from '../../core/theming';
import type { Theme } from '../../types';

Expand Down
4 changes: 2 additions & 2 deletions src/components/FAB/AnimatedFAB/AnimatedFAB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {
TextLayoutEventData,
} from 'react-native';
import { white, black } from '../../../styles/themes/v2/colors';
import AnimatedText from '../../Typography/AnimatedText';
import AnimatedText from '../../Typography/v2/AnimatedText';
import { getCombinedStyles } from './utils';

export type AnimatedFABIconMode = 'static' | 'dynamic';
Expand Down Expand Up @@ -151,7 +151,7 @@ const AnimatedFAB = ({
.rgb()
.string();

const { backgroundColor = disabled ? disabledColor : theme.colors?.accent } =
const { backgroundColor = disabled ? disabledColor : theme?.colors?.accent } =
StyleSheet.flatten<ViewStyle>(style) || {};

let foregroundColor: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/FAB/FAB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const FAB = ({
.rgb()
.string();

const { backgroundColor = disabled ? disabledColor : theme.colors?.accent } =
const { backgroundColor = disabled ? disabledColor : theme?.colors?.accent } =
(StyleSheet.flatten(style) || {}) as ViewStyle;

let foregroundColor;
Expand Down
2 changes: 1 addition & 1 deletion src/components/HelperText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TextStyle,
LayoutChangeEvent,
} from 'react-native';
import AnimatedText from './Typography/AnimatedText';
import AnimatedText from './Typography/v2/AnimatedText';
import { withTheme } from '../core/theming';
import type { $Omit, Theme } from '../types';

Expand Down
9 changes: 6 additions & 3 deletions src/components/List/ListAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,11 @@ const ListAccordion = ({
}
};

const titleColor = color(theme.colors?.text).alpha(0.87).rgb().string();
const descriptionColor = color(theme.colors?.text).alpha(0.54).rgb().string();
const titleColor = color(theme?.colors?.text).alpha(0.87).rgb().string();
const descriptionColor = color(theme?.colors?.text)
.alpha(0.54)
.rgb()
.string();

const expandedInternal = expandedProp !== undefined ? expandedProp : expanded;

Expand All @@ -189,7 +192,7 @@ const ListAccordion = ({
: handlePressAction;
return (
<View>
<View style={{ backgroundColor: theme.colors?.background }}>
<View style={{ backgroundColor: theme?.colors?.background }}>
<TouchableRipple
style={[styles.container, style]}
onPress={handlePress}
Expand Down
7 changes: 5 additions & 2 deletions src/components/List/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const ListItem = ({
};

const renderTitle = () => {
const titleColor = color(theme.colors?.text).alpha(0.87).rgb().string();
const titleColor = color(theme?.colors?.text).alpha(0.87).rgb().string();

return typeof title === 'function' ? (
title({
Expand All @@ -198,7 +198,10 @@ const ListItem = ({
);
};

const descriptionColor = color(theme.colors?.text).alpha(0.54).rgb().string();
const descriptionColor = color(theme?.colors?.text)
.alpha(0.54)
.rgb()
.string();

return (
<TouchableRipple
Expand Down
Loading

0 comments on commit f0be14c

Please sign in to comment.