LiveLocationSharingViewer: Handle map loading error UI.

This commit is contained in:
SBiOSoftWhare
2022-08-01 12:45:59 +02:00
parent d264c6e1ac
commit 2261747643
3 changed files with 47 additions and 27 deletions
@@ -57,6 +57,8 @@ struct LiveLocationSharingViewerViewState: BindableState {
var isBottomSheetVisible: Bool {
return isAllLocationSharingEnded == false
}
var showMapLoadingError: Bool = false
let errorSubject = PassthroughSubject<LocationSharingViewError, Never>()
@@ -105,6 +105,10 @@ class LiveLocationSharingViewerViewModel: LiveLocationSharingViewerViewModelType
return
}
if case .failedLoadingMap = error {
state.showMapLoadingError = true
}
let alertInfo = mapViewErrorAlertInfoBuilder.build(with: error) { [weak self] in
switch error {
@@ -37,40 +37,53 @@ struct LiveLocationSharingViewer: View {
var body: some View {
ZStack(alignment: .bottom) {
LocationSharingMapView(tileServerMapURL: viewModel.viewState.mapStyleURL,
annotations: viewModel.viewState.annotations,
highlightedAnnotation: viewModel.viewState.highlightedAnnotation,
userAvatarData: nil,
showsUserLocation: false,
userAnnotationCanShowCallout: true,
userLocation: Binding.constant(nil),
mapCenterCoordinate: Binding.constant(nil),
onCalloutTap: { annotation in
if let userLocationAnnotation = annotation as? UserLocationAnnotation {
viewModel.send(viewAction: .share(userLocationAnnotation))
}
},
errorSubject: viewModel.viewState.errorSubject)
if viewModel.viewState.isBottomSheetVisible {
VStack(alignment: .center) {
Spacer()
MapCreditsView(action: {
viewModel.send(viewAction: .mapCreditsDidTap)
})
.offset(y: -(bottomSheetCollapsedHeight)) // Put the copyright action above the collapsed bottom sheet
.padding(.bottom, 10)
if !viewModel.viewState.showMapLoadingError {
LocationSharingMapView(tileServerMapURL: viewModel.viewState.mapStyleURL,
annotations: viewModel.viewState.annotations,
highlightedAnnotation: viewModel.viewState.highlightedAnnotation,
userAvatarData: nil,
showsUserLocation: false,
userAnnotationCanShowCallout: true,
userLocation: Binding.constant(nil),
mapCenterCoordinate: Binding.constant(nil),
onCalloutTap: { annotation in
if let userLocationAnnotation = annotation as? UserLocationAnnotation {
viewModel.send(viewAction: .share(userLocationAnnotation))
}
},
errorSubject: viewModel.viewState.errorSubject)
// Show map credits above collapsed bottom sheet height if bottom sheet is visible
if viewModel.viewState.isBottomSheetVisible {
VStack(alignment: .center) {
Spacer()
MapCreditsView(action: {
viewModel.send(viewAction: .mapCreditsDidTap)
})
.offset(y: -(bottomSheetCollapsedHeight)) // Put the copyright action above the collapsed bottom sheet
.padding(.bottom, 10)
}
.ignoresSafeArea()
}
.ignoresSafeArea()
} else {
MapLoadingErrorView()
.padding(.bottom, viewModel.viewState.isBottomSheetVisible ? bottomSheetCollapsedHeight : 0)
}
if viewModel.viewState.isAllLocationSharingEnded {
VStack(alignment: .center) {
Spacer()
MapCreditsView(action: {
viewModel.send(viewAction: .mapCreditsDidTap)
})
.padding(.bottom, 5)
// Show map credits only if map is visible
if !viewModel.viewState.showMapLoadingError {
MapCreditsView(action: {
viewModel.send(viewAction: .mapCreditsDidTap)
})
.padding(.bottom, 5)
}
HStack(spacing: 10) {
Image(uiImage: Asset.Images.locationLiveCellIcon.image)
.renderingMode(.template)
@@ -96,6 +109,7 @@ struct LiveLocationSharingViewer: View {
}
}
.accentColor(theme.colors.accent)
.background(theme.colors.system.ignoresSafeArea())
.bottomSheet(sheet, if: viewModel.viewState.isBottomSheetVisible)
.actionSheet(isPresented: $viewModel.showMapCreditsSheet) {
return MapCreditsActionSheet(openURL: { url in