MCPcopy Create free account
hub / github.com/callstack/react-native-paper / SurfaceExample

Function SurfaceExample

example/src/Examples/SurfaceExample.tsx:15–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13import ScreenWrapper from '../ScreenWrapper';
14
15const SurfaceExample = () => {
16 const { isV3 } = useExampleTheme();
17 const v2Elevation = [1, 2, 4, 8, 12];
18 const elevationValues = isV3 ? Array.from({ length: 6 }) : v2Elevation;
19
20 const renderSurface = (index: number, mode: 'flat' | 'elevated') => (
21 <Surface
22 key={index}
23 style={[
24 styles.surface,
25 isV3 ? styles.v3Surface : { elevation: v2Elevation[index] },
26 ]}
27 mode={mode}
28 {...(isV3 && { elevation: index as MD3Elevation })}
29 >
30 <Text variant="bodyLarge">
31 {isV3
32 ? `Elevation ${index === 1 ? '(default)' : ''} ${index}`
33 : `${elevationValues[index]}`}
34 </Text>
35 </Surface>
36 );
37
38 return (
39 <ScreenWrapper>
40 <List.Section title="Elevated surface">
41 <ScrollView horizontal showsHorizontalScrollIndicator={false}>
42 {elevationValues.map((_, index) => renderSurface(index, 'elevated'))}
43 </ScrollView>
44 </List.Section>
45
46 <List.Section title="Flat surface">
47 <ScrollView horizontal showsHorizontalScrollIndicator={false}>
48 {elevationValues.map((_, index) => renderSurface(index, 'flat'))}
49 </ScrollView>
50 </List.Section>
51
52 <List.Section title="Layout">
53 <View style={styles.content}>
54 <View style={styles.horizontalSurfacesContainer}>
55 <Surface style={styles.horizontalSurface}>
56 <Text style={styles.centerText}>Left</Text>
57 </Surface>
58 <Surface style={styles.horizontalSurface}>
59 <Text style={styles.centerText}>Right</Text>
60 </Surface>
61 </View>
62 <View style={styles.verticalSurfacesContainer}>
63 <Surface style={styles.verticalSurface}>
64 <Text style={styles.centerText}>Top</Text>
65 </Surface>
66 <Surface style={styles.verticalSurface}>
67 <Text style={styles.centerText}>Bottom</Text>
68 </Surface>
69 </View>
70 </View>
71 </List.Section>
72 </ScreenWrapper>

Callers

nothing calls this directly

Calls 2

useExampleThemeFunction · 0.90
renderSurfaceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…