5720: Update UI in location sharing View

This commit is contained in:
MaximeE
2022-03-17 16:52:22 +01:00
parent d5a878ccad
commit dedc558f44
16 changed files with 241 additions and 32 deletions
@@ -0,0 +1,61 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import SwiftUI
@available(iOS 14.0, *)
struct LocationSharingOptionButton<Content: View>: View {
// MARK: - Properties
// MARK: Private
@Environment(\.theme) private var theme: ThemeSwiftUI
let text: String
let action: () -> (Void)
@ViewBuilder var content: Content
var body: some View {
Button(action: action) {
HStack(spacing: 18) {
content
.frame(width: 40, height: 40)
Text(text)
.font(theme.fonts.body)
.foregroundColor(theme.colors.primaryContent)
}
}
}
}
@available(iOS 14.0, *)
struct LocationSharingOptionButton_Previews: PreviewProvider {
static var previews: some View {
VStack {
LocationSharingOptionButton(text: "Share my current location") {
} content: {
LocationSharingUserMarkerView(isMarker: false, avatarData: AvatarInput(mxContentUri: "", matrixItemId: "test", displayName: "Nicolas"))
}
LocationSharingOptionButton(text: "Share live location") {
} content: {
LocationSharingOptionButtonIcon(fillColor: Color.purple, image: Asset.Images.locationLiveIcon.image)
}
}
}
}
@@ -0,0 +1,48 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import SwiftUI
@available(iOS 14.0, *)
struct LocationSharingOptionButtonIcon: View {
// MARK: - Properties
// MARK: Private
@Environment(\.theme) private var theme: ThemeSwiftUI
let fillColor: Color
let image: UIImage
var body: some View {
ZStack {
Circle()
.fill(fillColor)
.frame(width: 40, height: 40)
Image(uiImage: image)
.renderingMode(.template)
.foregroundColor(Color.white)
}
}
}
@available(iOS 14.0, *)
struct LocationSharingOptionButtonIcon_Previews: PreviewProvider {
static var previews: some View {
LocationSharingOptionButtonIcon(fillColor: Color.green, image: Asset.Images.locationMarkerIcon.image)
}
}
@@ -27,19 +27,35 @@ struct LocationSharingUserMarkerView: View {
@State private var frame: CGRect = .zero
private var usernameColorGenerator: UserNameColorGenerator {
let usernameColorGenerator = UserNameColorGenerator()
let theme = ThemeService.shared().theme
usernameColorGenerator.defaultColor = theme.textPrimaryColor
usernameColorGenerator.userNameColors = theme.userNameColors
return usernameColorGenerator
}
// MARK: Public
let isMarker: Bool
let avatarData: AvatarInputProtocol
var body: some View {
let fillColor: Color = Color(usernameColorGenerator.color(from:avatarData.matrixItemId))
ZStack {
Image(uiImage: Asset.Images.locationUserMarker.image)
AvatarImage(avatarData: avatarData, size: .large)
.offset(y: -1.5)
Circle()
.fill(fillColor)
.frame(width: 40, height: 40)
if isMarker {
Rectangle()
.rotation(Angle(degrees: 45))
.fill(fillColor)
.frame(width: 7, height: 7)
.offset(x: 0, y: 19)
}
AvatarImage(avatarData: avatarData, size: .small)
}
.background(ViewFrameReader(frame: $frame))
.padding(.bottom, frame.height)
.accentColor(theme.colors.accent)
}
}
@@ -49,9 +65,11 @@ struct LocationSharingUserMarkerView: View {
struct LocationSharingUserMarkerView_Previews: PreviewProvider {
static var previews: some View {
let avatarData = AvatarInput(mxContentUri: "",
matrixItemId: "",
matrixItemId: "test",
displayName: "Alice")
LocationSharingUserMarkerView(avatarData: avatarData)
VStack(alignment: .center, spacing: 15) {
LocationSharingUserMarkerView(isMarker: true, avatarData: avatarData)
LocationSharingUserMarkerView(isMarker: false, avatarData: avatarData)
}
}
}
@@ -32,16 +32,22 @@ struct LocationSharingView: View {
var body: some View {
NavigationView {
ZStack(alignment: .bottom) {
LocationSharingMapView(tileServerMapURL: context.viewState.mapStyleURL,
annotations: context.viewState.annotations,
highlightedAnnotation: context.viewState.highlightedAnnotation,
userAvatarData: context.viewState.userAvatarData,
showsUserLocation: context.viewState.showsUserLocation,
userLocation: $context.userLocation,
errorSubject: context.viewState.errorSubject)
.ignoresSafeArea()
MapCreditsView()
VStack {
ZStack(alignment: .bottom) {
LocationSharingMapView(tileServerMapURL: context.viewState.mapStyleURL,
annotations: context.viewState.annotations,
highlightedAnnotation: context.viewState.highlightedAnnotation,
userAvatarData: context.viewState.userAvatarData,
showsUserLocation: context.viewState.showsUserLocation,
userLocation: $context.userLocation,
errorSubject: context.viewState.errorSubject)
.ignoresSafeArea()
MapCreditsView()
}
if context.viewState.shareButtonVisible {
buttonsView
.cornerRadius(5)
}
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
@@ -63,11 +69,6 @@ struct LocationSharingView: View {
.accessibilityIdentifier("LocationSharingView.shareButton")
}
.disabled(!context.viewState.shareButtonEnabled)
} else {
Button(VectorL10n.locationSharingShareAction, action: {
context.send(viewAction: .share)
})
.disabled(!context.viewState.shareButtonEnabled)
}
}
}
@@ -84,6 +85,38 @@ struct LocationSharingView: View {
.navigationViewStyle(StackNavigationViewStyle())
}
var buttonsView: some View {
VStack(alignment: .leading, spacing: 15) {
if !context.viewState.isPinDropSharing {
LocationSharingOptionButton(text: VectorL10n.locationSharingStaticShareTitle) {
context.send(viewAction: .share)
} content: {
LocationSharingUserMarkerView(isMarker: false, avatarData: context.viewState.userAvatarData)
}
.disabled(!context.viewState.shareButtonEnabled)
// Disable for now until live location sharing is done
if BuildSettings.liveLocationSharingEnabled {
LocationSharingOptionButton(text: VectorL10n.locationSharingLiveShareTitle) {
// TODO: - Start live location sharing
} content: {
LocationSharingOptionButtonIcon(fillColor: Color.purple, image: Asset.Images.locationLiveIcon.image)
}
.disabled(!context.viewState.shareButtonEnabled)
}
} else {
LocationSharingOptionButton(text: VectorL10n.locationSharingPinDropShareTitle) {
// TODO: - Pin drop sharing action
} content: {
LocationSharingOptionButtonIcon(fillColor:
theme.colors.primaryContent, image: Asset.Images.locationMarkerIcon.image)
}
.disabled(!context.viewState.shareButtonEnabled)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
}
@ViewBuilder
private var activityIndicator: some View {
if context.viewState.showLoadingIndicator {
@@ -45,7 +45,7 @@ class UserLocationAnnotatonView: MGLUserLocationAnnotationView {
private func addUserMarkerView(with avatarData: AvatarInputProtocol) {
guard let avatarImageView = UIHostingController(rootView: LocationSharingUserMarkerView(avatarData: avatarData)).view else {
guard let avatarImageView = UIHostingController(rootView: LocationSharingUserMarkerView(isMarker: true, avatarData: avatarData)).view else {
return
}