|
1 | | -import {View, StyleSheet} from 'react-native'; |
| 1 | +import React from 'react'; |
| 2 | +import { |
| 3 | + Text, |
| 4 | + Platform, |
| 5 | + ScrollView, |
| 6 | + StyleSheet, |
| 7 | + SafeAreaView, |
| 8 | + type TextStyle, |
| 9 | + useColorScheme, |
| 10 | +} from 'react-native'; |
| 11 | +import Haptics from '@mhpdev/react-native-haptics'; |
| 12 | +import HapticButton from './components/HapticButton'; |
| 13 | +import {AndroidHaptics, Impacts, Notifications} from './core/config'; |
2 | 14 |
|
3 | 15 | export default function App() { |
| 16 | + const scheme = useColorScheme(); |
| 17 | + |
| 18 | + const titleStyle = React.useMemo<TextStyle>(() => { |
| 19 | + return { |
| 20 | + fontSize: 20, |
| 21 | + fontWeight: 'bold', |
| 22 | + textAlign: 'center', |
| 23 | + marginVertical: 10, |
| 24 | + color: scheme === 'dark' ? 'white' : 'black', |
| 25 | + }; |
| 26 | + }, [scheme]); |
| 27 | + |
4 | 28 | return ( |
5 | | - <View style={styles.container}> |
6 | | - <></> |
7 | | - </View> |
| 29 | + <SafeAreaView style={styles.container}> |
| 30 | + <Text style={titleStyle}>React Native Haptics Examples</Text> |
| 31 | + <ScrollView |
| 32 | + showsVerticalScrollIndicator={false} |
| 33 | + contentContainerStyle={styles.content}> |
| 34 | + <Text style={titleStyle}>Haptics Impacts</Text> |
| 35 | + {Impacts.map(impact => ( |
| 36 | + <HapticButton |
| 37 | + key={impact.name} |
| 38 | + title={impact.name} |
| 39 | + onPress={() => Haptics.impact(impact.style)} |
| 40 | + /> |
| 41 | + ))} |
| 42 | + <Text style={titleStyle}>Haptics Notfications</Text> |
| 43 | + {Notifications.map(notification => ( |
| 44 | + <HapticButton |
| 45 | + key={notification.name} |
| 46 | + title={notification.name} |
| 47 | + onPress={() => Haptics.notification(notification.type)} |
| 48 | + /> |
| 49 | + ))} |
| 50 | + <Text style={titleStyle}>Haptics Selection</Text> |
| 51 | + <HapticButton title="Selection" onPress={Haptics.selection} /> |
| 52 | + {Platform.OS !== 'android' ? null : ( |
| 53 | + <React.Fragment> |
| 54 | + <Text style={titleStyle}>Android Haptics</Text> |
| 55 | + {AndroidHaptics.map(haptic => ( |
| 56 | + <HapticButton |
| 57 | + key={haptic.name} |
| 58 | + title={haptic.name} |
| 59 | + onPress={() => Haptics.androidHaptics(haptic.type)} |
| 60 | + /> |
| 61 | + ))} |
| 62 | + </React.Fragment> |
| 63 | + )} |
| 64 | + </ScrollView> |
| 65 | + </SafeAreaView> |
8 | 66 | ); |
9 | 67 | } |
10 | 68 |
|
11 | 69 | const styles = StyleSheet.create({ |
12 | 70 | container: { |
13 | 71 | flex: 1, |
| 72 | + paddingVertical: 30, |
| 73 | + }, |
| 74 | + content: { |
| 75 | + marginTop: 10, |
| 76 | + paddingBottom: 40, |
14 | 77 | alignItems: 'center', |
15 | | - justifyContent: 'center', |
16 | 78 | }, |
17 | 79 | }); |
0 commit comments