|
| 1 | +import React from 'react'; |
| 2 | +import { Pressable, StyleSheet, Text, View } from 'react-native'; |
| 3 | + |
| 4 | +export default function FeedbackEvents() { |
| 5 | + const [eventLog, updateEventLog] = React.useState([]); |
| 6 | + |
| 7 | + const handlePress = eventName => { |
| 8 | + return () => { |
| 9 | + const limit = 6; |
| 10 | + updateEventLog(state => { |
| 11 | + const nextState = state.slice(0, limit - 1); |
| 12 | + nextState.unshift(eventName); |
| 13 | + return nextState; |
| 14 | + }); |
| 15 | + }; |
| 16 | + }; |
| 17 | + |
| 18 | + return ( |
| 19 | + <View> |
| 20 | + <View> |
| 21 | + <Pressable |
| 22 | + onLongPress={handlePress('longPress')} |
| 23 | + onPress={handlePress('press')} |
| 24 | + onPressIn={handlePress('pressIn')} |
| 25 | + onPressOut={handlePress('pressOut')} |
| 26 | + > |
| 27 | + <View> |
| 28 | + <Text style={styles.touchableText}>Press Me</Text> |
| 29 | + </View> |
| 30 | + </Pressable> |
| 31 | + </View> |
| 32 | + |
| 33 | + <View> |
| 34 | + <Pressable |
| 35 | + accessibilityRole="none" |
| 36 | + onLongPress={handlePress('longPress')} |
| 37 | + onPress={handlePress('press')} |
| 38 | + onPressIn={handlePress('pressIn')} |
| 39 | + onPressOut={handlePress('pressOut')} |
| 40 | + style={({ pressed, focused }) => ({ |
| 41 | + padding: 10, |
| 42 | + margin: 10, |
| 43 | + borderWidth: 1, |
| 44 | + borderColor: focused ? 'blue' : null, |
| 45 | + backgroundColor: pressed ? 'lightblue' : 'white' |
| 46 | + })} |
| 47 | + > |
| 48 | + <Pressable |
| 49 | + accessibilityRole="none" |
| 50 | + onLongPress={handlePress('longPress - inner')} |
| 51 | + onPress={handlePress('press - inner')} |
| 52 | + onPressIn={handlePress('pressIn - inner')} |
| 53 | + onPressOut={handlePress('pressOut - inner')} |
| 54 | + style={({ pressed, focused }) => ({ |
| 55 | + padding: 10, |
| 56 | + margin: 10, |
| 57 | + borderWidth: 1, |
| 58 | + borderColor: focused ? 'blue' : null, |
| 59 | + backgroundColor: pressed ? 'lightblue' : 'white' |
| 60 | + })} |
| 61 | + > |
| 62 | + <Text>Nested pressables</Text> |
| 63 | + </Pressable> |
| 64 | + </Pressable> |
| 65 | + </View> |
| 66 | + |
| 67 | + <View style={styles.eventLogBox}> |
| 68 | + {eventLog.map((e, ii) => ( |
| 69 | + <Text key={ii}>{e}</Text> |
| 70 | + ))} |
| 71 | + </View> |
| 72 | + </View> |
| 73 | + ); |
| 74 | +} |
| 75 | + |
| 76 | +const styles = StyleSheet.create({ |
| 77 | + touchableText: { |
| 78 | + borderRadius: 8, |
| 79 | + padding: 5, |
| 80 | + borderWidth: 1, |
| 81 | + borderColor: 'black', |
| 82 | + color: '#007AFF', |
| 83 | + borderStyle: 'solid', |
| 84 | + textAlign: 'center' |
| 85 | + }, |
| 86 | + eventLogBox: { |
| 87 | + padding: 10, |
| 88 | + marginTop: 10, |
| 89 | + height: 120, |
| 90 | + borderWidth: StyleSheet.hairlineWidth, |
| 91 | + borderColor: '#f0f0f0', |
| 92 | + backgroundColor: '#f9f9f9' |
| 93 | + } |
| 94 | +}); |
0 commit comments