Guest User

Untitled

a guest
Apr 9th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {View, Text, TouchableOpacity, TextInput} from 'react-native';
  2. import React, {useRef} from 'react';
  3. import {BottomTabBarProps} from '@react-navigation/bottom-tabs';
  4. import Icon from '../assets/icons/add_icon.svg';
  5. import RBSheet from 'react-native-raw-bottom-sheet';
  6. import ActionSheet from 'react-native-actions-sheet';
  7.  
  8. function BottomTabBar({state, descriptors, navigation}: BottomTabBarProps) {
  9.   const renderTabs = () => {
  10.     return state.routes.map((route, index) => {
  11.       const {options} = descriptors[route.key];
  12.       const label =
  13.         options.tabBarLabel !== undefined
  14.           ? options.tabBarLabel
  15.           : options.title !== undefined
  16.           ? options.title
  17.           : route.name;
  18.  
  19.       const isFocused = state.index === index;
  20.  
  21.       const onPress = () => {
  22.         const event = navigation.emit({
  23.           type: 'tabPress',
  24.           target: route.key,
  25.           canPreventDefault: true,
  26.         });
  27.  
  28.         if (!isFocused && !event.defaultPrevented) {
  29.           navigation.navigate(route.name);
  30.         }
  31.       };
  32.  
  33.       const onLongPress = () => {
  34.         navigation.emit({
  35.           type: 'tabLongPress',
  36.           target: route.key,
  37.         });
  38.       };
  39.  
  40.       const onAddPress = (ref: React.MutableRefObject<RBSheet>) => {
  41.         const event = navigation.emit({
  42.           type: 'tabPress',
  43.           target: route.key,
  44.           canPreventDefault: true,
  45.         });
  46.  
  47.         event.preventDefault();
  48.         ref.current.open();
  49.       };
  50.  
  51.       if (route.name === 'Add') {
  52.         const refRBSheet = useRef() as React.MutableRefObject<RBSheet>;
  53.         let actionSheet: any;
  54.         return (
  55.           <TouchableOpacity
  56.             style={{backgroundColor: 'transparent'}}
  57.             hitSlop={{top: 50}}
  58.             activeOpacity={1}
  59.             onPress={() => {
  60.               actionSheet.setModalVisible();
  61.             }}>
  62.             <View
  63.               style={{
  64.                 justifyContent: 'center',
  65.                 flex: 1,
  66.                 backgroundColor: 'white',
  67.               }}>
  68.               <View
  69.                 style={{
  70.                   width: 80,
  71.                   height: 80,
  72.                   elevation: 4,
  73.                   borderRadius: 40,
  74.                   top: -30,
  75.                   alignSelf: 'center',
  76.                 }}>
  77.                 <Icon width={80} height={80} style={{alignSelf: 'center'}} />
  78.               </View>
  79.               <ActionSheet
  80.                 bounceOnOpen
  81.                 bounciness={15}
  82.                 defaultOverlayOpacity={0}
  83.                 ref={(ref) => (actionSheet = ref)}
  84.                 gestureEnabled={true}
  85.                 openAnimationSpeed={100}
  86.                 CustomHeaderComponent={
  87.                   <View
  88.                     style={{
  89.                       backgroundColor: 'transparent',
  90.                       borderRadius: 15,
  91.                       height: 40,
  92.                     }}>
  93.                     <View
  94.                       style={{
  95.                         width: 80,
  96.                         height: 80,
  97.                         elevation: 4,
  98.                         borderRadius: 40,
  99.                         top: -50,
  100.                         alignSelf: 'center',
  101.                       }}>
  102.                       <Icon
  103.                         width={80}
  104.                         height={80}
  105.                         style={{alignSelf: 'center'}}
  106.                       />
  107.                     </View>
  108.                   </View>
  109.                 }>
  110.                 <View
  111.                   style={{
  112.                     height: 300,
  113.                     padding: 15,
  114.                     backgroundColor: 'teal',
  115.                     borderTopRightRadius: 15,
  116.                     borderTopLeftRadius: 15,
  117.                   }}>
  118.                   <TextInput
  119.                     underlineColorAndroid="white"
  120.                     placeholderTextColor="white"
  121.                     placeholder="Todo title.."
  122.                   />
  123.                 </View>
  124.               </ActionSheet>
  125.             </View>
  126.           </TouchableOpacity>
  127.         );
  128.       }
  129.  
  130.       return (
  131.         <TouchableOpacity
  132.           accessibilityRole="button"
  133.           activeOpacity={1}
  134.           accessibilityStates={isFocused ? ['selected'] : []}
  135.           accessibilityLabel={options.tabBarAccessibilityLabel}
  136.           testID={options.tabBarTestID}
  137.           onPress={onPress}
  138.           onLongPress={onLongPress}
  139.           style={{
  140.             flex: 1,
  141.             height: 50,
  142.             backgroundColor: 'white',
  143.             justifyContent: 'center',
  144.             alignItems: 'center',
  145.           }}>
  146.           <Text style={{color: isFocused ? 'orange' : '#5F87E7'}}>{label}</Text>
  147.         </TouchableOpacity>
  148.       );
  149.     });
  150.   };
  151.  
  152.   return <View style={{flexDirection: 'row'}}>{renderTabs()}</View>;
  153. }
  154.  
  155. const MySheet = () => (
  156.   <View
  157.     style={{
  158.       height: 700,
  159.       position: 'relative',
  160.       width: '100%',
  161.       backgroundColor: 'orange',
  162.       borderTopLeftRadius: 15,
  163.       borderTopRightRadius: 15,
  164.     }}>
  165.     <Icon
  166.       style={{
  167.         position: 'absolute',
  168.         alignSelf: 'center',
  169.         top: -40,
  170.       }}
  171.     />
  172.     <TextInput placeholder="Your Todo.." />
  173.   </View>
  174. );
  175.  
  176. export default BottomTabBar;
Add Comment
Please, Sign In to add comment