-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3082 from digitalfabrik/1258-bottom-sheet-scrolling
2189: Refactor and upgrade pois and bottom sheet
- Loading branch information
Showing
15 changed files
with
271 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React, { ReactElement } from 'react' | ||
import styled from 'styled-components/native' | ||
|
||
const Handle = styled.View` | ||
width: 34px; | ||
border: 1px solid ${props => props.theme.colors.textSecondaryColor}; | ||
background-color: ${props => props.theme.colors.textSecondaryColor}; | ||
border-radius: 10px; | ||
align-self: center; | ||
margin: 20px 0; | ||
` | ||
|
||
const BottomSheetHandle = (): ReactElement => <Handle /> | ||
|
||
export default BottomSheetHandle |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import BottomSheet, { | ||
BottomSheetFlatList, | ||
BottomSheetFlatListMethods, | ||
BottomSheetScrollView, | ||
} from '@gorhom/bottom-sheet' | ||
import React, { memo, ReactElement, Ref } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { Platform } from 'react-native' | ||
import styled from 'styled-components/native' | ||
|
||
import { LocationType } from 'shared' | ||
import { ErrorCode, PoiModel } from 'shared/api' | ||
|
||
import useCityAppContext from '../hooks/useCityAppContext' | ||
import BottomSheetHandle from './BottomSheetHandle' | ||
import Failure from './Failure' | ||
import { NoItemsMessage } from './List' | ||
import PoiDetails from './PoiDetails' | ||
import PoiListItem from './PoiListItem' | ||
|
||
const StyledBottomSheet = styled(BottomSheet)<{ isFullscreen: boolean }>` | ||
${props => props.isFullscreen && `background-color: ${props.theme.colors.backgroundColor};`} | ||
` | ||
|
||
const BottomSheetContent = styled.View` | ||
flex: 1; | ||
margin: 0 24px; | ||
` | ||
|
||
const Title = styled.Text` | ||
color: ${props => props.theme.colors.textColor}; | ||
font-family: ${props => props.theme.fonts.native.decorativeFontBold}; | ||
font-size: 18px; | ||
font-weight: bold; | ||
` | ||
|
||
type PoiBottomSheetProps = { | ||
poiListRef: Ref<BottomSheetFlatListMethods> | ||
pois: PoiModel[] | ||
poi: PoiModel | undefined | ||
userLocation: LocationType | null | ||
slug: string | undefined | ||
selectPoi: (poi: PoiModel) => void | ||
deselectAll: () => void | ||
snapPoints: number[] | ||
snapPointIndex: number | ||
setSnapPointIndex: (index: number) => void | ||
setScrollPosition: (position: number) => void | ||
isFullscreen: boolean | ||
} | ||
|
||
const PoisBottomSheet = ({ | ||
poiListRef, | ||
pois, | ||
poi, | ||
userLocation, | ||
slug, | ||
selectPoi, | ||
deselectAll, | ||
snapPoints, | ||
snapPointIndex, | ||
setSnapPointIndex, | ||
setScrollPosition, | ||
isFullscreen, | ||
}: PoiBottomSheetProps): ReactElement | null => { | ||
const { languageCode } = useCityAppContext() | ||
const { t } = useTranslation('pois') | ||
// ios has scrolling issues if content panning gesture is not enabled | ||
const enableContentPanningGesture = Platform.OS === 'ios' || !isFullscreen | ||
|
||
const PoiDetail = poi ? ( | ||
<PoiDetails language={languageCode} poi={poi} distance={userLocation && poi.distance(userLocation)} /> | ||
) : ( | ||
<Failure code={ErrorCode.PageNotFound} buttonAction={deselectAll} buttonLabel={t('detailsHeader')} /> | ||
) | ||
|
||
const renderPoiListItem = ({ item: poi }: { item: PoiModel }): ReactElement => ( | ||
<PoiListItem | ||
key={poi.path} | ||
poi={poi} | ||
language={languageCode} | ||
navigateToPoi={() => selectPoi(poi)} | ||
distance={userLocation && poi.distance(userLocation)} | ||
/> | ||
) | ||
|
||
return ( | ||
<StyledBottomSheet | ||
index={snapPointIndex} | ||
isFullscreen={isFullscreen} | ||
snapPoints={snapPoints} | ||
enableContentPanningGesture={enableContentPanningGesture} | ||
enableDynamicSizing={false} | ||
animateOnMount | ||
handleComponent={BottomSheetHandle} | ||
onChange={setSnapPointIndex}> | ||
<BottomSheetContent> | ||
{slug ? ( | ||
<BottomSheetScrollView showsVerticalScrollIndicator={false}>{PoiDetail}</BottomSheetScrollView> | ||
) : ( | ||
<BottomSheetFlatList | ||
ref={poiListRef} | ||
data={pois} | ||
role='list' | ||
renderItem={renderPoiListItem} | ||
onMomentumScrollBegin={event => setScrollPosition(event.nativeEvent.contentOffset.y)} | ||
showsVerticalScrollIndicator={false} | ||
ListHeaderComponent={<Title>{t('listTitle')}</Title>} | ||
ListEmptyComponent={<NoItemsMessage>{t('noPois')}</NoItemsMessage>} | ||
/> | ||
)} | ||
</BottomSheetContent> | ||
</StyledBottomSheet> | ||
) | ||
} | ||
|
||
export default memo(PoisBottomSheet) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.