Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adjust theme types to match internal and regular usage #3279

Merged
merged 16 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
363 changes: 244 additions & 119 deletions docs/pages/2.theming.md

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions example/index.d.ts

This file was deleted.

11 changes: 5 additions & 6 deletions example/src/DrawerItems.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import * as React from 'react';
import { View, StyleSheet, I18nManager } from 'react-native';
import { I18nManager, StyleSheet, View } from 'react-native';

import { DrawerContentScrollView } from '@react-navigation/drawer';
import * as Updates from 'expo-updates';
import {
Badge,
Drawer,
MD2Colors,
MD3Colors,
Switch,
Text,
TouchableRipple,
MD2Colors,
useTheme,
MD3Colors,
} from 'react-native-paper';

import { isWeb } from '../utils';

import { PreferencesContext } from './';
import { PreferencesContext, useExampleTheme } from './';

type Props = {
toggleTheme: () => void;
Expand Down Expand Up @@ -97,7 +96,7 @@ const DrawerItems = ({

const _setDrawerItem = (index: number) => setDrawerItemIndex(index);

const { colors, isV3 } = useTheme();
const { isV3, colors } = useExampleTheme();

const _handleToggleRTL = () => {
toggleRTL();
Expand Down
6 changes: 4 additions & 2 deletions example/src/ExampleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { FlatList } from 'react-native';

import type { StackNavigationProp } from '@react-navigation/stack';
import { List, Divider, useTheme } from 'react-native-paper';
import { Divider, List } from 'react-native-paper';
import { useSafeArea } from 'react-native-safe-area-context';

import ActivityIndicatorExample from './Examples/ActivityIndicatorExample';
Expand Down Expand Up @@ -41,6 +41,8 @@ import ThemeExample from './Examples/ThemeExample';
import ToggleButtonExample from './Examples/ToggleButtonExample';
import TouchableRippleExample from './Examples/TouchableRippleExample';

import { useExampleTheme } from '.';

export const examples: Record<
string,
React.ComponentType<any> & { title: string }
Expand Down Expand Up @@ -105,7 +107,7 @@ export default function ExampleList({ navigation }: Props) {

const keyExtractor = (item: { id: string }) => item.id;

const { colors } = useTheme();
const { colors } = useExampleTheme();
const safeArea = useSafeArea();

return (
Expand Down
8 changes: 4 additions & 4 deletions example/src/Examples/ActivityIndicatorExample.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as React from 'react';
import { View, StyleSheet } from 'react-native';
import { StyleSheet, View } from 'react-native';

import {
ActivityIndicator,
MD2Colors,
FAB,
useTheme,
MD2Colors,
MD3Colors,
} from 'react-native-paper';

import { useExampleTheme } from '..';
import ScreenWrapper from '../ScreenWrapper';

const ActivityIndicatorExample = () => {
const [animating, setAnimating] = React.useState<boolean>(true);
const { isV3 } = useTheme();
const { isV3 } = useExampleTheme();

return (
<ScreenWrapper style={styles.container}>
Expand Down
10 changes: 5 additions & 5 deletions example/src/Examples/AnimatedFABExample/AnimatedFABExample.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as React from 'react';
import { View, StyleSheet, FlatList, Animated, Platform } from 'react-native';
import type { NativeSyntheticEvent, NativeScrollEvent } from 'react-native';
import type { NativeScrollEvent, NativeSyntheticEvent } from 'react-native';
import { Animated, FlatList, Platform, StyleSheet, View } from 'react-native';

import {
Avatar,
MD2Colors,
MD3Colors,
useTheme,
Avatar,
Paragraph,
Text,
} from 'react-native-paper';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';

import { useExampleTheme } from '../..';
import { animatedFABExampleData } from '../../../utils';
import CustomFAB from './CustomFAB';
import CustomFABControls, {
Expand All @@ -32,7 +32,7 @@ type Item = {
};

const AnimatedFABExample = () => {
const { colors, isV3 } = useTheme();
const { colors, isV3 } = useExampleTheme();

const isIOS = Platform.OS === 'ios';

Expand Down
12 changes: 7 additions & 5 deletions example/src/Examples/AnimatedFABExample/CustomFAB.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';
import {
StyleProp,
ViewStyle,
Animated,
StyleSheet,
Platform,
StyleProp,
StyleSheet,
ViewStyle,
} from 'react-native';

import { AnimatedFAB, useTheme } from 'react-native-paper';
import { AnimatedFAB } from 'react-native-paper';

import { useExampleTheme } from '../..';

type CustomFABProps = {
animatedValue: Animated.Value;
Expand All @@ -29,7 +31,7 @@ const CustomFAB = ({
iconMode,
}: CustomFABProps) => {
const [isExtended, setIsExtended] = React.useState(true);
const { isV3 } = useTheme();
const { isV3 } = useExampleTheme();

const isIOS = Platform.OS === 'ios';

Expand Down
10 changes: 6 additions & 4 deletions example/src/Examples/AnimatedFABExample/CustomFABControls.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import { StyleSheet, View, FlatList } from 'react-native';
import { FlatList, StyleSheet, View } from 'react-native';

import { TouchableOpacity } from 'react-native-gesture-handler';
import type {
AnimatedFABAnimateFrom,
AnimatedFABIconMode,
} from 'react-native-paper';
import { Paragraph, RadioButton, Text, useTheme } from 'react-native-paper';
import { Paragraph, RadioButton, Text } from 'react-native-paper';

import { useExampleTheme } from '../..';

export type Controls = {
iconMode: AnimatedFABIconMode;
Expand Down Expand Up @@ -38,7 +40,7 @@ const CustomControl = ({
value,
onChange,
}: CustomControlProps) => {
const { isV3 } = useTheme();
const { isV3 } = useExampleTheme();

const _renderItem = React.useCallback(
({ item }) => {
Expand Down Expand Up @@ -85,7 +87,7 @@ const CustomFABControls = ({
setControls,
controls: { animateFrom, iconMode },
}: Props) => {
const { colors } = useTheme();
const { colors } = useExampleTheme();

const setIconMode = (newIconMode: AnimatedFABIconMode) =>
setControls((state) => ({ ...state, iconMode: newIconMode }));
Expand Down
12 changes: 6 additions & 6 deletions example/src/Examples/AppbarExample.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as React from 'react';
import { View, Platform, StyleSheet } from 'react-native';
import { Platform, StyleSheet, View } from 'react-native';

import type { StackNavigationProp } from '@react-navigation/stack';
import {
Appbar,
FAB,
Switch,
List,
Paragraph,
Text,
useTheme,
RadioButton,
List,
Switch,
Text,
} from 'react-native-paper';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

import { useExampleTheme } from '..';
import { yellowA200 } from '../../../src/styles/themes/v2/colors';
import ScreenWrapper from '../ScreenWrapper';

Expand All @@ -37,7 +37,7 @@ const AppbarExample = ({ navigation }: Props) => {
const [showCalendarIcon, setShowCalendarIcon] = React.useState(false);
const [showElevated, setShowElevated] = React.useState(false);

const theme = useTheme();
const theme = useExampleTheme();
const { bottom, left, right } = useSafeAreaInsets();
const height = theme.isV3 ? 80 : 56;

Expand Down
13 changes: 4 additions & 9 deletions example/src/Examples/AvatarExample.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import * as React from 'react';
import { View, StyleSheet } from 'react-native';
import { StyleSheet, View } from 'react-native';

import {
Avatar,
List,
MD2Colors,
MD3Colors,
useTheme,
} from 'react-native-paper';
import { Avatar, List, MD2Colors, MD3Colors } from 'react-native-paper';

import { useExampleTheme } from '..';
import ScreenWrapper from '../ScreenWrapper';

const AvatarExample = () => {
const { isV3 } = useTheme();
const { isV3 } = useExampleTheme();
return (
<ScreenWrapper>
<List.Section title="Text">
Expand Down
10 changes: 5 additions & 5 deletions example/src/Examples/BadgeExample.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import * as React from 'react';
import { View, StyleSheet } from 'react-native';
import { StyleSheet, View } from 'react-native';

import {
Badge,
IconButton,
List,
Paragraph,
Switch,
MD2Colors,
useTheme,
MD3Colors,
Paragraph,
Switch,
} from 'react-native-paper';

import { useExampleTheme } from '..';
import ScreenWrapper from '../ScreenWrapper';

const BadgeExample = () => {
const [visible, setVisible] = React.useState<boolean>(true);
const { isV3 } = useTheme();
const { isV3 } = useExampleTheme();

return (
<ScreenWrapper>
Expand Down
13 changes: 4 additions & 9 deletions example/src/Examples/BannerExample.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import * as React from 'react';
import { View, StyleSheet, Image, Dimensions, Platform } from 'react-native';
import { Dimensions, Image, Platform, StyleSheet, View } from 'react-native';

import {
Banner,
FAB,
useTheme,
MD2Colors,
MD3Colors,
} from 'react-native-paper';
import { Banner, FAB, MD2Colors, MD3Colors } from 'react-native-paper';

import { useExampleTheme } from '..';
import ScreenWrapper from '../ScreenWrapper';

const PHOTOS = Array.from({ length: 24 }).map(
Expand All @@ -18,7 +13,7 @@ const PHOTOS = Array.from({ length: 24 }).map(
const BannerExample = () => {
const [visible, setVisible] = React.useState<boolean>(true);
const [useCustomTheme, setUseCustomTheme] = React.useState<boolean>(false);
const defaultTheme = useTheme();
const defaultTheme = useExampleTheme();
const customTheme = !defaultTheme.isV3
? {
...defaultTheme,
Expand Down
13 changes: 7 additions & 6 deletions example/src/Examples/BottomNavigationExample.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import * as React from 'react';
import {
View,
Image,
Dimensions,
StyleSheet,
Platform,
Easing,
Image,
Platform,
StyleSheet,
View,
} from 'react-native';

import type { StackNavigationProp } from '@react-navigation/stack';
import { Appbar, BottomNavigation, Menu, useTheme } from 'react-native-paper';
import { Appbar, BottomNavigation, Menu } from 'react-native-paper';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

import { useExampleTheme } from '..';
import ScreenWrapper from '../ScreenWrapper';

type RoutesState = Array<{
Expand Down Expand Up @@ -54,7 +55,7 @@ const PhotoGallery = ({ route }: Route) => {
};

const BottomNavigationExample = ({ navigation }: Props) => {
const { isV3 } = useTheme();
const { isV3 } = useExampleTheme();
const insets = useSafeAreaInsets();
const [index, setIndex] = React.useState(0);
const [menuVisible, setMenuVisible] = React.useState(false);
Expand Down
7 changes: 4 additions & 3 deletions example/src/Examples/ButtonExample.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as React from 'react';
import { View, StyleSheet, Image } from 'react-native';
import { Image, StyleSheet, View } from 'react-native';

import { Button, List, useTheme } from 'react-native-paper';
import { Button, List } from 'react-native-paper';

import { useExampleTheme } from '..';
import ScreenWrapper from '../ScreenWrapper';

const ButtonExample = () => {
const theme = useTheme();
const theme = useExampleTheme();

const color = theme.isV3 ? theme.colors.inversePrimary : theme.colors.accent;

Expand Down
11 changes: 5 additions & 6 deletions example/src/Examples/CardExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ import { Alert, ScrollView, StyleSheet, View } from 'react-native';

import {
Avatar,
Paragraph,
Card,
Button,
IconButton,
useTheme,
Card,
Chip,
IconButton,
Paragraph,
Text,
} from 'react-native-paper';

import { PreferencesContext } from '..';
import { PreferencesContext, useExampleTheme } from '..';
import { isWeb } from '../../utils';
import ScreenWrapper from '../ScreenWrapper';

type Mode = 'elevated' | 'outlined' | 'contained';

const CardExample = () => {
const { colors, isV3 } = useTheme();
const { colors, isV3 } = useExampleTheme();
const [selectedMode, setSelectedMode] = React.useState('elevated' as Mode);
const [isSelected, setIsSelected] = React.useState(false);
const preferences = React.useContext(PreferencesContext);
Expand Down
Loading