diff --git a/example/package.json b/example/package.json
index f532cb981c..d855195aa8 100644
--- a/example/package.json
+++ b/example/package.json
@@ -15,7 +15,6 @@
"@react-native-async-storage/async-storage": "2.2.0",
"@react-native-masked-view/masked-view": "0.3.2",
"@react-navigation/bottom-tabs": "^8.0.0-alpha.57",
- "@react-navigation/drawer": "^8.0.0-alpha.58",
"@react-navigation/elements": "3.0.0-alpha.55",
"@react-navigation/native": "^8.0.0-alpha.51",
"@react-navigation/native-stack": "^8.0.0-alpha.59",
diff --git a/example/src/DrawerItems.tsx b/example/src/DrawerItems.tsx
deleted file mode 100644
index e205164f1b..0000000000
--- a/example/src/DrawerItems.tsx
+++ /dev/null
@@ -1,317 +0,0 @@
-import * as React from 'react';
-import { Platform, StyleSheet, View } from 'react-native';
-import type { ColorValue } from 'react-native';
-
-import { DrawerContentScrollView } from '@react-navigation/drawer';
-import Constants, { ExecutionEnvironment } from 'expo-constants';
-import {
- Badge,
- Button,
- Dialog,
- Drawer,
- Palette,
- Switch,
- Text,
- TouchableRipple,
- useTheme,
-} from 'react-native-paper';
-
-import { dynamicThemeSupported } from '../utils';
-import { PreferencesContext } from './PreferencesContext';
-
-const DrawerItemsData = [
- {
- label: 'Inbox',
- icon: 'inbox',
- key: 0,
- right: () => 44,
- },
- {
- label: 'Starred',
- icon: 'star',
- key: 1,
- right: ({ color }: { color: ColorValue }) => (
-
- ),
- },
- { label: 'Sent mail', icon: 'send', key: 2 },
- { label: 'Colored label', icon: 'palette', key: 3 },
- {
- label: 'A very long title that will be truncated',
- icon: 'delete',
- key: 4,
- right: () => ,
- },
-];
-
-const DrawerCollapsedItemsData = [
- {
- label: 'Inbox',
- focusedIcon: 'inbox',
- unfocusedIcon: 'inbox-outline',
- key: 0,
- badge: 44,
- },
- {
- label: 'Starred',
- focusedIcon: 'star',
- unfocusedIcon: 'star-outline',
- key: 1,
- },
- {
- label: 'Sent mail',
- focusedIcon: 'send',
- unfocusedIcon: 'send-outline',
- key: 2,
- },
- {
- label: 'A very long title that will be truncated',
- focusedIcon: 'delete',
- unfocusedIcon: 'delete-outline',
- key: 3,
- },
- {
- label: 'Full width',
- focusedIcon: 'arrow-all',
- key: 4,
- },
- {
- focusedIcon: 'bell',
- unfocusedIcon: 'bell-outline',
- key: 5,
- badge: true,
- },
-];
-
-function DrawerItems() {
- const [drawerItemIndex, setDrawerItemIndex] = React.useState(0);
- const [showRTLDialog, setShowRTLDialog] = React.useState(false);
- const preferences = React.useContext(PreferencesContext);
-
- const _setDrawerItem = (index: number) => setDrawerItemIndex(index);
-
- const { colors } = useTheme();
- const expoGoExecution =
- Constants.executionEnvironment === ExecutionEnvironment.StoreClient;
-
- if (!preferences) throw new Error('PreferencesContext not provided');
-
- const {
- toggleShouldUseDynamicTheme,
- toggleTheme,
- toggleRtl: toggleRTL,
- toggleCollapsed,
- toggleCustomFont,
- toggleRippleEffect,
- customFontLoaded,
- rippleEffectEnabled,
- collapsed,
- rtl: isRTL,
- theme: { dark: isDarkTheme },
- shouldUseDynamicTheme,
- } = preferences;
-
- const _handleToggleRTL = () => {
- if (Platform.OS !== 'web' && expoGoExecution) {
- setShowRTLDialog(true);
- return;
- }
-
- toggleRTL();
- };
-
- const _handleDismissRTLDialog = () => {
- setShowRTLDialog(false);
- };
-
- const coloredLabelTheme = {
- colors: {
- secondaryContainer: Palette.tertiary80,
- onSecondaryContainer: Palette.tertiary20,
- },
- };
-
- return (
-
- {collapsed && (
-
- {DrawerCollapsedItemsData.map((props, index) => (
- {
- _setDrawerItem(index);
- index === 4 && toggleCollapsed();
- }}
- />
- ))}
-
- )}
- {!collapsed && (
- <>
-
- {DrawerItemsData.map((props, index) => (
- _setDrawerItem(index)}
- />
- ))}
-
-
-
- {dynamicThemeSupported ? (
-
-
- Use Dynamic Theme
-
-
-
-
-
- ) : null}
-
-
- Dark Theme
-
-
-
-
-
-
-
-
- RTL
-
-
-
-
-
-
-
-
- Collapsed drawer *
-
-
-
-
-
-
-
-
- Custom font *
-
-
-
-
-
-
-
-
-
- {Platform.OS === 'ios' ? 'Highlight' : 'Ripple'} effect *
-
-
-
-
-
-
-
- {!collapsed && (
-
- * - optional example toggles
-
- )}
-
- React Native Paper Version{' '}
- {require('react-native-paper/package.json').version}
-
- >
- )}
-
- );
-}
-
-const styles = StyleSheet.create({
- drawerContent: {
- flex: 1,
- },
- preference: {
- flexDirection: 'row',
- justifyContent: 'space-between',
- alignItems: 'center',
- paddingVertical: 12,
- paddingHorizontal: 16,
- },
- v3Preference: {
- height: 56,
- paddingHorizontal: 28,
- },
- badge: {
- alignSelf: 'center',
- },
- collapsedSection: {
- marginTop: 16,
- },
- annotation: {
- marginHorizontal: 24,
- marginVertical: 6,
- },
-});
-
-export default DrawerItems;
diff --git a/example/src/ExampleList.tsx b/example/src/ExampleList.tsx
index 2af1eed385..17d719b5b1 100644
--- a/example/src/ExampleList.tsx
+++ b/example/src/ExampleList.tsx
@@ -1,9 +1,11 @@
-import { FlatList } from 'react-native';
+import { useState } from 'react';
+import { FlatList, StyleSheet, View } from 'react-native';
import { useNavigation } from '@react-navigation/native';
-import { Divider, List, useTheme } from 'react-native-paper';
+import { Divider, List, Text, useTheme } from 'react-native-paper';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
+import ExampleListHeader from './ExampleListHeader';
import ActivityIndicatorExample from './Examples/ActivityIndicatorExample';
import AppbarExample from './Examples/AppbarExample';
import AvatarExample from './Examples/AvatarExample';
@@ -46,6 +48,8 @@ import ThemeExample from './Examples/ThemeExample';
import ThemingWithReactNavigation from './Examples/ThemingWithReactNavigation';
import TooltipExample from './Examples/TooltipExample';
import TouchableRippleExample from './Examples/TouchableRippleExample';
+import { filterByQuery } from '../utils/filterByQuery';
+import { objectEntries } from '../utils/typedObject';
export const mainExamples = {
ActivityIndicator: ActivityIndicatorExample,
@@ -101,7 +105,7 @@ export const examples = {
...nestedExamples,
};
-const data = Object.entries(mainExamples).map(([id, example]) => ({
+const data = objectEntries(mainExamples).map(([id, example]) => ({
id,
data: example,
}));
@@ -112,32 +116,62 @@ export default function ExampleList() {
const { colors } = useTheme();
const safeArea = useSafeAreaInsets();
+ const [query, setQuery] = useState('');
+
+ const filteredData = filterByQuery(data, query, ({ id, data: example }) => [
+ example.title,
+ id,
+ ]);
+
return (
- (
- {
- // @ts-expect-error TypeScript can't call overloaded functions with union arguments.
- // https://github.com/microsoft/TypeScript/issues/40803
- navigation.navigate(item.id);
- }}
- />
- )}
- keyExtractor={({ id }) => id}
- data={data}
- />
+
+
+ (
+ {
+ // @ts-expect-error TypeScript can't call overloaded functions with union arguments.
+ // https://github.com/microsoft/TypeScript/issues/40803
+ navigation.navigate(item.id);
+ }}
+ />
+ )}
+ ListEmptyComponent={
+
+ {`No examples match "${query.trim()}"`}
+
+ }
+ keyExtractor={({ id }) => id}
+ data={filteredData}
+ />
+
);
}
+
+const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ },
+ empty: {
+ padding: 16,
+ textAlign: 'center',
+ },
+});
diff --git a/example/src/ExampleListHeader.tsx b/example/src/ExampleListHeader.tsx
new file mode 100644
index 0000000000..eaf08e2ca3
--- /dev/null
+++ b/example/src/ExampleListHeader.tsx
@@ -0,0 +1,43 @@
+import { StyleSheet } from 'react-native';
+
+import { useNavigation } from '@react-navigation/native';
+import { Appbar, Searchbar } from 'react-native-paper';
+
+import PreferencesAction from './Preferences/PreferencesAction';
+
+type Props = {
+ query: string;
+ onQueryChange: (query: string) => void;
+};
+
+export default function ExampleListHeader({ query, onQueryChange }: Props) {
+ const navigation = useNavigation('ExampleList');
+
+ const canGoBack = navigation.canGoBack();
+
+ return (
+
+ navigation.goBack() : undefined}
+ searchAccessibilityLabel={canGoBack ? 'go back' : 'search'}
+ clearAccessibilityLabel="clear search"
+ autoCorrect={false}
+ autoCapitalize="none"
+ style={styles.searchbar}
+ />
+
+
+ );
+}
+
+const styles = StyleSheet.create({
+ searchbar: {
+ flex: 1,
+ },
+});
diff --git a/example/src/Examples/CardExample.tsx b/example/src/Examples/CardExample.tsx
index 09b732d9d0..ed8842e40c 100644
--- a/example/src/Examples/CardExample.tsx
+++ b/example/src/Examples/CardExample.tsx
@@ -11,7 +11,7 @@ import {
useTheme,
} from 'react-native-paper';
-import { PreferencesContext } from '../PreferencesContext';
+import { usePreferences } from '../Preferences/usePreferences';
import ScreenWrapper from '../ScreenWrapper';
type Mode = 'elevated' | 'outlined' | 'contained';
@@ -20,7 +20,7 @@ const CardExample = () => {
const { colors } = useTheme();
const [selectedMode, setSelectedMode] = React.useState('elevated');
const [isSelected, setIsSelected] = React.useState(false);
- const preferences = React.useContext(PreferencesContext);
+ const { toggleTheme } = usePreferences();
const modes: Mode[] = ['elevated', 'outlined', 'contained'];
@@ -193,13 +193,7 @@ const CardExample = () => {
- {
- preferences?.toggleTheme();
- }}
- mode={selectedMode}
- >
+
}
diff --git a/example/src/Examples/SearchbarExample.tsx b/example/src/Examples/SearchbarExample.tsx
index 1a3e98bb8f..fbe936bbd5 100644
--- a/example/src/Examples/SearchbarExample.tsx
+++ b/example/src/Examples/SearchbarExample.tsx
@@ -11,10 +11,12 @@ import {
useTheme,
} from 'react-native-paper';
+import { usePreferences } from '../Preferences/usePreferences';
import ScreenWrapper from '../ScreenWrapper';
const SearchExample = () => {
const navigation = useNavigation('Searchbar');
+ const { togglePreferences } = usePreferences();
const [isVisible, setIsVisible] = React.useState(false);
const [searchQueries, setSearchQuery] = React.useState({
@@ -27,7 +29,7 @@ const SearchExample = () => {
searchWithoutBottomLine: '',
loadingViewMode: '',
clickableBack: '',
- clickableDrawer: '',
+ clickablePreferences: '',
clickableLoading: '',
});
@@ -185,15 +187,15 @@ const SearchExample = () => {
onChangeText={(query) =>
setSearchQuery({
...searchQueries,
- clickableDrawer: query,
+ clickablePreferences: query,
})
}
- value={searchQueries.clickableDrawer}
+ value={searchQueries.clickablePreferences}
onIconPress={() => {
Keyboard.dismiss();
- navigation.openDrawer();
+ togglePreferences();
}}
- icon="menu"
+ icon="cog"
style={styles.searchbar}
/>
{
- const preferences = React.useContext(PreferencesContext);
+ const { toggleTheme } = usePreferences();
const [options, setOptions] = React.useState({
showSnackbar: false,
@@ -31,9 +31,7 @@ const SnackbarExample = () => {
const action = {
label: showLongerAction ? 'Toggle Theme' : 'Action',
- onPress: () => {
- preferences?.toggleTheme();
- },
+ onPress: toggleTheme,
};
return (
diff --git a/example/src/Preferences/PreferencesAction.tsx b/example/src/Preferences/PreferencesAction.tsx
new file mode 100644
index 0000000000..a4e791900b
--- /dev/null
+++ b/example/src/Preferences/PreferencesAction.tsx
@@ -0,0 +1,15 @@
+import { Appbar } from 'react-native-paper';
+
+import { usePreferences } from './usePreferences';
+
+export default function PreferencesAction() {
+ const { togglePreferences } = usePreferences();
+
+ return (
+
+ );
+}
diff --git a/example/src/Preferences/PreferencesContext.tsx b/example/src/Preferences/PreferencesContext.tsx
new file mode 100644
index 0000000000..c89d41e69a
--- /dev/null
+++ b/example/src/Preferences/PreferencesContext.tsx
@@ -0,0 +1,21 @@
+import { createContext } from 'react';
+
+import type { Theme } from 'react-native-paper';
+
+export type Preferences = {
+ toggleTheme: () => void;
+ toggleRtl: () => void;
+ toggleCustomFont: () => void;
+ togglePreferences: () => void;
+ toggleRippleEffect: () => void;
+ toggleShouldUseDynamicTheme: () => void;
+ resetPreferences: () => void;
+ theme: Theme;
+ rtl: boolean;
+ customFontLoaded: boolean;
+ preferencesVisible: boolean;
+ rippleEffectEnabled: boolean;
+ shouldUseDynamicTheme: boolean;
+};
+
+export const PreferencesContext = createContext(null);
diff --git a/example/src/Preferences/PreferencesModal.tsx b/example/src/Preferences/PreferencesModal.tsx
new file mode 100644
index 0000000000..d05111ce39
--- /dev/null
+++ b/example/src/Preferences/PreferencesModal.tsx
@@ -0,0 +1,201 @@
+import { useState } from 'react';
+import {
+ Platform,
+ ScrollView,
+ StyleSheet,
+ useWindowDimensions,
+ View,
+} from 'react-native';
+
+import Constants, { ExecutionEnvironment } from 'expo-constants';
+import {
+ Button,
+ Dialog,
+ Modal,
+ Switch,
+ Text,
+ useTheme,
+} from 'react-native-paper';
+
+import { usePreferences } from './usePreferences';
+import { dynamicThemeSupported } from '../../utils';
+
+export default function PreferencesModal() {
+ const [showRTLDialog, setShowRTLDialog] = useState(false);
+ const theme = useTheme();
+ const { height: windowHeight } = useWindowDimensions();
+
+ const expoGoExecution =
+ Constants.executionEnvironment === ExecutionEnvironment.StoreClient;
+ const rtlToggleUnavailable = Platform.OS !== 'web' && expoGoExecution;
+ const rippleEffectLabel = `${Platform.OS === 'ios' ? 'Highlight' : 'Ripple'} effect`;
+
+ const {
+ toggleShouldUseDynamicTheme,
+ toggleTheme,
+ toggleRtl,
+ toggleCustomFont,
+ toggleRippleEffect,
+ togglePreferences,
+ resetPreferences,
+ preferencesVisible,
+ customFontLoaded,
+ rippleEffectEnabled,
+ rtl,
+ theme: { dark: isDarkTheme },
+ shouldUseDynamicTheme,
+ } = usePreferences();
+
+ const _handleToggleRTL = () => {
+ if (rtlToggleUnavailable) {
+ setShowRTLDialog(true);
+ return;
+ }
+
+ toggleRtl();
+ };
+
+ const _handleDismissRTLDialog = () => {
+ setShowRTLDialog(false);
+ };
+
+ return (
+ <>
+
+
+ {dynamicThemeSupported ? (
+
+ Use Dynamic Theme
+
+
+ ) : null}
+
+ Dark Theme
+
+
+
+
+ RTL
+
+
+
+
+ Custom font *
+
+
+
+
+ {rippleEffectLabel} *
+
+
+
+
+
+
+ * - optional example toggles
+
+
+ React Native Paper Version{' '}
+ {require('react-native-paper/package.json').version}
+
+
+
+