Merge pull request #5859 from vector-im/maximee/5720_location_sharing_UI_change

Update UI in location sharing view #5720
This commit is contained in:
MaximeEvrard42
2022-03-24 11:58:09 +01:00
committed by GitHub
34 changed files with 301 additions and 49 deletions
@@ -42,7 +42,7 @@ struct AvatarImage: View {
.resizable()
}
}
.frame(width: CGFloat(size.rawValue), height: CGFloat(size.rawValue))
.frame(maxWidth: CGFloat(size.rawValue), maxHeight: CGFloat(size.rawValue))
.clipShape(Circle())
.onAppear {
viewModel.inject(dependencies: dependencies)
@@ -69,6 +69,19 @@ extension AvatarImage {
}
}
@available(iOS 14.0, *)
extension AvatarImage {
func border(color: Color) -> some View {
modifier(BorderModifier(color: color, borderWidth: 3, shape: Circle()))
}
/// Use display name color as border color by default
func border() -> some View {
let borderColor = theme.userColor(for: matrixItemId)
return self.border(color: borderColor)
}
}
@available(iOS 14.0, *)
struct AvatarImage_Previews: PreviewProvider {
static let mxContentUri = "fakeUri"
@@ -52,7 +52,7 @@ class AvatarViewModel: InjectableObject, ObservableObject {
return
}
avatarService.avatarImage(mxContentUri: mxContentUri, avatarSize: avatarSize)
avatarService.avatarImage(mxContentUri: mxContentUri, avatarSize: avatarSize)
.sink { completion in
guard case let .failure(error) = completion else { return }
UILog.error("[AvatarService] Failed to retrieve avatar: \(error)")
@@ -20,10 +20,10 @@ import SwiftUI
@available(iOS 14.0, *)
extension ThemeSwiftUI {
/// Get the stable display name color based on userId.
/// Get the stable display user color based on userId.
/// - Parameter userId: The user id used to hash.
/// - Returns: The SwiftUI color for the associated userId.
func displayNameColor(for userId: String) -> Color {
func userColor(for userId: String) -> Color {
let senderNameColorIndex = Int(userId.vc_hashCode % Int32(colors.namesAndAvatars.count))
return colors.namesAndAvatars[senderNameColorIndex]
}
@@ -0,0 +1,37 @@
//
// 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 BorderModifier<Shape: InsettableShape>: ViewModifier {
var color: Color
var borderWidth: CGFloat
var shape: Shape
func body(content: Content) -> some View {
content
.overlay(shape.stroke(color, lineWidth: borderWidth))
}
}
@available(iOS 14.0, *)
extension View {
func shapedBorder<Shape: InsettableShape>(color: Color, borderWidth: CGFloat, shape: Shape) -> some View {
modifier(BorderModifier(color: color, borderWidth: borderWidth, shape: shape))
}
}