Skip to content

Commit

Permalink
Merge pull request #9 from milad-alizadeh/bug-fix-bottom-sheet-loadin…
Browse files Browse the repository at this point in the history
…g-indicator

Bug fix bottom sheet loading indicator
  • Loading branch information
milad-alizadeh authored Dec 19, 2023
2 parents 034e073 + a626cc2 commit 5af148c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 28 deletions.
30 changes: 12 additions & 18 deletions src/components/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const BottomSheet = forwardRef(function BottomSheet(
const topInset = useSafeAreaInsets().top
const windowHeight = useWindowDimensions().height
const windowWidth = useWindowDimensions().width
const bottomInset = useSafeAreaInsets().bottom
const contentHeight = useSharedValue(0)
const blurIntensity = useSharedValue(0)
const [isReady, setIsReady] = useState(false)
Expand All @@ -65,10 +64,9 @@ export const BottomSheet = forwardRef(function BottomSheet(

setTimeout(() => {
setVisible(false)
onHide && onHide()
onHide?.()
setIsReady(false)
}, duration)

setIsReady(false)
}

useImperativeHandle(
Expand All @@ -93,13 +91,6 @@ export const BottomSheet = forwardRef(function BottomSheet(
],
}
})

const closeStyle = useAnimatedStyle(() => {
return {
opacity: withTiming(paddingTop.value > 0 ? 1 : 0, animationConfig),
}
})

const intensityProp = useAnimatedProps(() => {
return {
intensity: withTiming(blurIntensity.value, animationConfig),
Expand All @@ -115,9 +106,8 @@ export const BottomSheet = forwardRef(function BottomSheet(
contentHeight.value = newContentHeight
paddingTop.value = isLargerThanWindow ? topInset : 0
offset.value = -newContentHeight
setIsReady(true)
}

setIsReady(true)
}

const swipeGesture = Gesture.Pan().onEnd((event) => {
Expand All @@ -138,7 +128,7 @@ export const BottomSheet = forwardRef(function BottomSheet(
<View className="left-0 top-0 h-screen w-screen" />
</Pressable>

{isReady && (
{!isReady && (
<ActivityIndicator
color={colors.white}
className="absolute top-1/2 left-1/2 -translate-x-2 -translate-y-2"
Expand All @@ -151,13 +141,17 @@ export const BottomSheet = forwardRef(function BottomSheet(
<ScrollView>
<View onLayout={onContentLayout}>
<Animated.View
style={closeStyle}
className="z-10 justify-center items-center rounded-full absolute right-6 top-5"
className={`z-10 justify-center items-center rounded-full absolute right-6 top-5`}
>
<Icon icon="close" size="large" accessibilityLabel='Close Modal' accessibilityRole="button" onPress={hide} />
<Icon
icon="close"
size="large"
accessibilityLabel="Close Modal"
accessibilityRole="button"
onPress={hide}
/>
</Animated.View>
{children}
<View style={{ height: bottomInset }} />
</View>
</ScrollView>

Expand Down
2 changes: 0 additions & 2 deletions src/components/DetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export const DetailsModal = () => {
useEffect(() => {
if (currentIngredientId || currentEquipmentId) {
modalRef?.current?.show()
} else {
modalRef?.current?.hide()
}
}, [currentIngredientId, currentEquipmentId])

Expand Down
7 changes: 4 additions & 3 deletions src/components/EquipmentDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react'
import { ScrollView, View } from 'react-native'
import { GET_EQUIPMENT_DETAILS } from '~/graphql/queries/'
import { getImageUrl, imageSizes } from '~/utils/getImageUrl'
import { useSafeAreaInsetsStyle } from '~/utils/useSafeAreaInsetsStyle'
import { Text } from './Text'

/**
Expand All @@ -21,13 +22,13 @@ export const EquipmentDetails = function EquipmentDetails({ equipmentId }: Equip
const { data, loading } = useQuery(GET_EQUIPMENT_DETAILS, {
variables: { equipmentId },
})

const inset = useSafeAreaInsetsStyle(['bottom'], 'margin')
const equipment = data?.equipmentCollection.edges[0]?.node

return (
<>
{!loading && (
<ScrollView className="p-6 pt-6 flex-">
{!loading && data && (
<ScrollView className="px-6 pt-6 pb-3" style={inset}>
<View className="justify-end flex-1">
<View className="flex-1">
<Image
Expand Down
7 changes: 4 additions & 3 deletions src/components/IngredientDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useEffect } from 'react'
import { View } from 'react-native'
import { useFetchIngredientDetails, useSession } from '~/hooks'
import { useAnalytics } from '~/hooks/useAnalytics'
import { useSafeAreaInsetsStyle } from '~/utils/useSafeAreaInsetsStyle'
import { Button } from './Button'
import { Checkbox } from './Checkbox'
import { HorizontalList } from './HorizontalList'
Expand All @@ -27,7 +28,7 @@ export const IngredientDetails = function IngredientDetails({
}: IngredientDetailsProps) {
const path = usePathname()
const showCta = path !== '/add-ingredients'

const inset = useSafeAreaInsetsStyle(['bottom'], 'margin')
const { screen, capture } = useAnalytics()
const { isLoggedIn } = useSession()
const {
Expand All @@ -49,11 +50,11 @@ export const IngredientDetails = function IngredientDetails({
return (
<>
{loading || recipesLoading ? null : (
<View className="justify-start flex-1 p-6">
<View className="justify-start flex-1 px-6 pt-6 pb-3" style={inset}>
{/* Name */}
<View className="mb-3">
{ingredient?.name && (
<Text h2 weight="bold" testID="ingredient-name">
<Text h2 weight="bold" styleClassName="pr-10 flex-1" testID="ingredient-name">
{ingredient?.name}
</Text>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useFetchIngredientDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export const useFetchIngredientDetails = (ingredientId: string, onClosed: () =>

return {
ingredient,
loading,
recipesLoading,
loading: loading && !data,
recipesLoading: recipesLoading && !relatedRecipes,
availableRecipes,
addLoading,
isInMyBar,
Expand Down

0 comments on commit 5af148c

Please sign in to comment.