Skip to content

Commit

Permalink
feat(bus line details): expand/collapse on header press
Browse files Browse the repository at this point in the history
  • Loading branch information
danshilm committed Jul 27, 2022
1 parent a6a50ce commit bcb4679
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
37 changes: 31 additions & 6 deletions src/components/BusLineSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Ionicons } from '@expo/vector-icons';
import BottomSheet, { BottomSheetScrollView } from '@gorhom/bottom-sheet';
import { useFocusEffect } from '@react-navigation/native';
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
import { ActivityIndicator, Text, TouchableOpacity, View } from 'react-native';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import {
ActivityIndicator,
Text,
TouchableOpacity,
TouchableWithoutFeedback,
View,
} from 'react-native';
import { BusLineDocumentBusStop, BusLineDocumentData } from '../interfaces/busline';
import tw from '../lib/tailwind';
import BusLineStopCard from './BusLineStopCard';
Expand All @@ -23,12 +29,13 @@ export default function BusLineSheet({
const maxOrder = busLine?.['bus-stops']?.length ?? 0;
const origin = busLine?.direction[direction].origin.name;
const destination = busLine?.direction[direction].destination.name;
const [sheetPositionIndex, setSheetPositionIndex] = useState(0);

const renderItem = useCallback(
(data: BusLineDocumentBusStop, index: number) => (
<BusLineStopCard data={data} maxOrder={maxOrder} index={index} key={index} />
),
[]
[maxOrder]
);

const HandleComponent = () => {
Expand All @@ -45,8 +52,23 @@ export default function BusLineSheet({
}
}, [busLine, loading]);

const handleSheetHeaderPress = () => {
// expand sheet if minimised
if (sheetPositionIndex === 0 || sheetPositionIndex === 1) {
sheetRef.current?.snapToIndex(2);
} else {
sheetRef.current?.snapToIndex(0);
}
};

return (
<BottomSheet snapPoints={snapPoints} ref={sheetRef} index={1} handleComponent={HandleComponent}>
<BottomSheet
snapPoints={snapPoints}
ref={sheetRef}
index={1}
handleComponent={HandleComponent}
onChange={setSheetPositionIndex}
>
{loading ? (
<ActivityIndicator size="large" style={tw`flex-1`} />
) : !busLine ? (
Expand All @@ -56,7 +78,10 @@ export default function BusLineSheet({
) : (
<View style={tw`flex-1`}>
{/* Header */}
<View style={tw`h-[15] rounded-[10px]`}>
<TouchableWithoutFeedback
style={tw`h-[15] rounded-[10px]`}
onPress={handleSheetHeaderPress}
>
<View style={tw`flex-row items-center mx-2`}>
<View style={tw`items-center justify-center h-15 w-17`}>
<TouchableOpacity style={tw`items-center justify-center w-8 h-8`}>
Expand All @@ -73,7 +98,7 @@ export default function BusLineSheet({
</Text>
)}
</View>
</View>
</TouchableWithoutFeedback>
{/* Divider */}
<View style={tw`h-px mx-3 bg-gray-600`} />
{error || !busLine.direction[direction]['bus-stops']?.length ? (
Expand Down
2 changes: 1 addition & 1 deletion src/screens/BusLineDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function BusLineDetails({
edgePadding: {
top: 100,
right: 50,
bottom: 300,
bottom: 400,
left: 50,
},
}
Expand Down

0 comments on commit bcb4679

Please sign in to comment.