Mini Sheet Snackbar
A hybrid snackbar/bottom-sheet for more complex notifications with actions.
Live preview. Clicks work like taps.
Add it in 3 steps
Copy the code yourself and see every line.
- 1
Install what it needs
Expo picks versions that match your app.Terminal$ npx expo install react-native - 2
Copy the component
Make a new file, for examplecomponents/MiniSheetSnackbar.tsx, and paste this in.components/MiniSheetSnackbar.tsx1import React, { useEffect, useRef } from 'react'; 2import { 3 StyleSheet, 4 View, 5 Text, 6 Animated, 7 PanResponder, 8 Dimensions, 9 TouchableOpacity, 10 Platform, 11} from 'react-native'; 12 13const { height: SCREEN_HEIGHT } = Dimensions.get('window'); 14const SHEET_HEIGHT = 220; 15 16interface Action { 17 label: string; 18 onPress: () => void; 19 primary?: boolean; 20} 21 22interface MiniSheetProps { 23 visible: boolean; 24 title: string; 25 description: string; 26 actions?: Action[]; 27 onClose: () => void; 28 theme?: 'light' | 'dark'; 29} 30 31const MiniSheetSnackbar = ({ 32 visible, 33 title, 34 description, 35 actions, 36 onClose, 37 theme = 'light' 38}: MiniSheetProps) => { 39 const translateY = useRef(new Animated.Value(SHEET_HEIGHT)).current; 40 41 const panResponder = useRef( 42 PanResponder.create({ 43 onStartShouldSetPanResponder: () => true, 44 onPanResponderMove: (_, gestureState) => { 45 if (gestureState.dy > 0) { 46 translateY.setValue(gestureState.dy); 47 } 48 }, 49 onPanResponderRelease: (_, gestureState) => { 50 if (gestureState.dy > 50 || gestureState.vy > 0.5) { 51 hide(); 52 } else { 53 show(); 54 } 55 }, 56 }) 57 ).current; 58 59 useEffect(() => { 60 if (visible) { 61 show(); 62 } else { 63 hide(); 64 } 65 }, [visible]); 66 67 const show = () => { 68 Animated.spring(translateY, { 69 toValue: 0, 70 useNativeDriver: true, 71 damping: 15, 72 stiffness: 100, 73 }).start(); 74 }; 75 76 const hide = () => { 77 Animated.timing(translateY, { 78 toValue: SHEET_HEIGHT, 79 duration: 250, 80 useNativeDriver: true, 81 }).start(() => onClose()); 82 }; 83 84 const isDark = theme === 'dark'; 85 86 return ( 87 <Animated.View 88 {...panResponder.panHandlers} 89 style={[ 90 styles.sheet, 91 { 92 backgroundColor: isDark ? '#1C1C1E' : '#FFFFFF', 93 transform: [{ translateY }], 94 }, 95 ]} 96 > 97 <View style={[styles.handle, { backgroundColor: isDark ? '#3A3A3C' : '#E5E7EB' }]} /> 98 99 <View style={styles.content}> 100 <Text style={[styles.title, { color: isDark ? '#FFFFFF' : '#111827' }]}> 101 {title} 102 </Text> 103 <Text style={[styles.description, { color: isDark ? '#A1A1AA' : '#6B7280' }]}> 104 {description} 105 </Text> 106 107 <View style={styles.actionRow}> 108 {actions?.map((action, index) => ( 109 <TouchableOpacity 110 key={index} 111 onPress={action.onPress} 112 style={[ 113 styles.button, 114 action.primary 115 ? { backgroundColor: '#6366F1' } 116 : { backgroundColor: isDark ? '#2C2C2E' : '#F3F4F6' }, 117 { flex: 1 } 118 ]} 119 > 120 <Text style={[ 121 styles.buttonText, 122 { color: action.primary ? '#FFFFFF' : (isDark ? '#FFFFFF' : '#111827') } 123 ]}> 124 {action.label} 125 </Text> 126 </TouchableOpacity> 127 ))} 128 </View> 129 </View> 130 </Animated.View> 131 ); 132}; 133 134const styles = StyleSheet.create({ 135 sheet: { 136 position: 'absolute', 137 bottom: 0, 138 left: 0, 139 right: 0, 140 height: SHEET_HEIGHT, 141 borderTopLeftRadius: 32, 142 borderTopRightRadius: 32, 143 paddingHorizontal: 24, 144 paddingTop: 12, 145 zIndex: 1000, 146 ...Platform.select({ 147 ios: { 148 shadowColor: '#000', 149 shadowOffset: { width: 0, height: -10 }, 150 shadowOpacity: 0.1, 151 shadowRadius: 10, 152 }, 153 android: { 154 elevation: 20, 155 }, 156 }), 157 }, 158 handle: { 159 width: 40, 160 height: 5, 161 borderRadius: 3, 162 alignSelf: 'center', 163 marginBottom: 20, 164 }, 165 content: { 166 flex: 1, 167 }, 168 title: { 169 fontSize: 20, 170 fontWeight: '800', 171 marginBottom: 8, 172 letterSpacing: -0.5, 173 }, 174 description: { 175 fontSize: 15, 176 lineHeight: 22, 177 marginBottom: 24, 178 }, 179 actionRow: { 180 flexDirection: 'row', 181 gap: 12, 182 }, 183 button: { 184 height: 50, 185 borderRadius: 14, 186 justifyContent: 'center', 187 alignItems: 'center', 188 }, 189 buttonText: { 190 fontSize: 15, 191 fontWeight: '700', 192 }, 193}); 194 195export default MiniSheetSnackbar; - 3
Use it
Import it on any page. Change the options to make it your own.page.tsx1// mini-sheet-snackbar 2import React, { useState } from 'react'; 3import { StyleSheet, View, Text, TouchableOpacity, SafeAreaView, StatusBar } from 'react-native'; 4import MiniSheetSnackbar from './components/MiniSheetSnackbar'; 5 6export default function App() { 7 const [sheetVisible, setSheetVisible] = useState(false); 8 9 const handleAction = (type: string) => { 10 console.log(`${type} pressed`); 11 setSheetVisible(false); 12 }; 13 14 return ( 15 <SafeAreaView style={styles.container}> 16 <StatusBar barStyle="dark-content" /> 17 18 <View style={styles.main}> 19 <Text style={styles.logo}>Uilora</Text> 20 <Text style={styles.sub}>Component Library</Text> 21 22 <TouchableOpacity 23 style={styles.trigger} 24 onPress={() => setSheetVisible(true)} 25 > 26 <Text style={styles.triggerText}>Open Confirmation</Text> 27 </TouchableOpacity> 28 </View> 29 30 <MiniSheetSnackbar 31 visible={sheetVisible} 32 theme="light" 33 title="Delete Session?" 34 description="Are you sure you want to sign out of this device? You will need to log in again to access your data." 35 onClose={() => setSheetVisible(false)} 36 actions={[ 37 { label: 'Cancel', onPress: () => handleAction('Cancel') }, 38 { label: 'Sign Out', onPress: () => handleAction('Delete'), primary: true }, 39 ]} 40 /> 41 </SafeAreaView> 42 ); 43} 44 45const styles = StyleSheet.create({ 46 container: { 47 flex: 1, 48 backgroundColor: '#F2F2F7', 49 }, 50 main: { 51 flex: 1, 52 justifyContent: 'center', 53 alignItems: 'center', 54 padding: 20, 55 }, 56 logo: { 57 fontSize: 42, 58 fontWeight: '900', 59 color: '#111827', 60 }, 61 sub: { 62 fontSize: 16, 63 color: '#6B7280', 64 marginBottom: 40, 65 }, 66 trigger: { 67 backgroundColor: '#111827', 68 paddingHorizontal: 24, 69 paddingVertical: 16, 70 borderRadius: 100, 71 }, 72 triggerText: { 73 color: 'white', 74 fontWeight: '700', 75 fontSize: 16, 76 } 77});
