mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Removed unused swipe gesture (+3 squashed commits)
Squashed commits: [d64bb3bb] Stop using the ServiceLocator directly in the ScreenTrackerViewModifier [37c46ab9] Rename Analytics to AnalyticsService [8852a371] #920 - Cleanup ServiceLocator usages
This commit is contained in:
committed by
Stefan Ceriu
parent
b4cd58b209
commit
e6711a0236
@@ -18,13 +18,15 @@ import SwiftUI
|
||||
|
||||
/// `ScreenTrackerViewModifier` is a helper class used to track PostHog screen from SwiftUI screens.
|
||||
struct ScreenTrackerViewModifier: ViewModifier {
|
||||
@Environment(\.analyticsService) private var analyticsService
|
||||
|
||||
let screen: AnalyticsScreen
|
||||
|
||||
@ViewBuilder
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.onAppear {
|
||||
ServiceLocator.shared.analytics.track(screen: screen)
|
||||
analyticsService.track(screen: screen)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
//
|
||||
// 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 Foundation
|
||||
import SwiftUI
|
||||
|
||||
extension View {
|
||||
func onSwipeGesture(minimumDistance: CGFloat,
|
||||
up: @escaping (() -> Void) = { },
|
||||
down: @escaping (() -> Void) = { },
|
||||
left: @escaping (() -> Void) = { },
|
||||
right: @escaping (() -> Void) = { }) -> some View {
|
||||
gesture(DragGesture(minimumDistance: minimumDistance, coordinateSpace: .local)
|
||||
.onEnded { value in
|
||||
if value.translation.width < 0 { left() }
|
||||
if value.translation.width > 0 { right() }
|
||||
if value.translation.height < 0 { up() }
|
||||
if value.translation.height > 0 { down() }
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,7 @@ extension UNMutableNotificationContent {
|
||||
return self
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
func addSenderIcon(using mediaProvider: MediaProviderProtocol?,
|
||||
senderID: String,
|
||||
senderName: String,
|
||||
|
||||
@@ -21,6 +21,11 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
|
||||
private let temporaryBlockquoteMarkingColor = UIColor.magenta
|
||||
private let temporaryCodeBlockMarkingColor = UIColor.cyan
|
||||
private let linkColor = UIColor.blue
|
||||
private let permalinkBaseURL: URL
|
||||
|
||||
init(permalinkBaseURL: URL) {
|
||||
self.permalinkBaseURL = permalinkBaseURL
|
||||
}
|
||||
|
||||
func fromPlain(_ string: String?) -> AttributedString? {
|
||||
guard let string else {
|
||||
@@ -169,7 +174,7 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
|
||||
attributedString.enumerateAttribute(.link, in: .init(location: 0, length: attributedString.length), options: []) { value, range, _ in
|
||||
if value != nil {
|
||||
if let url = value as? URL {
|
||||
switch PermalinkBuilder.detectPermalink(in: url) {
|
||||
switch PermalinkBuilder.detectPermalink(in: url, baseURL: permalinkBaseURL) {
|
||||
case .userIdentifier(let identifier):
|
||||
attributedString.addAttributes([.MatrixUserID: identifier], range: range)
|
||||
case .roomIdentifier(let identifier):
|
||||
|
||||
@@ -39,8 +39,8 @@ enum PermalinkBuilder {
|
||||
return charset
|
||||
}()
|
||||
|
||||
static func detectPermalink(in url: URL) -> PermalinkType? {
|
||||
guard url.absoluteString.hasPrefix(ServiceLocator.shared.settings.permalinkBaseURL.absoluteString) else {
|
||||
static func detectPermalink(in url: URL, baseURL: URL) -> PermalinkType? {
|
||||
guard url.absoluteString.hasPrefix(baseURL.absoluteString) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -78,12 +78,12 @@ enum PermalinkBuilder {
|
||||
return nil
|
||||
}
|
||||
|
||||
static func permalinkTo(userIdentifier: String) throws -> URL {
|
||||
static func permalinkTo(userIdentifier: String, baseURL: URL) throws -> URL {
|
||||
guard MatrixEntityRegex.isMatrixUserIdentifier(userIdentifier) else {
|
||||
throw PermalinkBuilderError.invalidUserIdentifier
|
||||
}
|
||||
|
||||
let urlString = "\(ServiceLocator.shared.settings.permalinkBaseURL)/#/\(userIdentifier)"
|
||||
let urlString = "\(baseURL)/#/\(userIdentifier)"
|
||||
|
||||
guard let url = URL(string: urlString) else {
|
||||
throw PermalinkBuilderError.failedConstructingURL
|
||||
@@ -92,23 +92,23 @@ enum PermalinkBuilder {
|
||||
return url
|
||||
}
|
||||
|
||||
static func permalinkTo(roomIdentifier: String) throws -> URL {
|
||||
static func permalinkTo(roomIdentifier: String, baseURL: URL) throws -> URL {
|
||||
guard MatrixEntityRegex.isMatrixRoomIdentifier(roomIdentifier) else {
|
||||
throw PermalinkBuilderError.invalidRoomIdentifier
|
||||
}
|
||||
|
||||
return try permalinkTo(roomIdentifierOrAlias: roomIdentifier)
|
||||
return try permalinkTo(roomIdentifierOrAlias: roomIdentifier, baseURL: baseURL)
|
||||
}
|
||||
|
||||
static func permalinkTo(roomAlias: String) throws -> URL {
|
||||
static func permalinkTo(roomAlias: String, baseURL: URL) throws -> URL {
|
||||
guard MatrixEntityRegex.isMatrixRoomAlias(roomAlias) else {
|
||||
throw PermalinkBuilderError.invalidRoomAlias
|
||||
}
|
||||
|
||||
return try permalinkTo(roomIdentifierOrAlias: roomAlias)
|
||||
return try permalinkTo(roomIdentifierOrAlias: roomAlias, baseURL: baseURL)
|
||||
}
|
||||
|
||||
static func permalinkTo(eventIdentifier: String, roomIdentifier: String) throws -> URL {
|
||||
static func permalinkTo(eventIdentifier: String, roomIdentifier: String, baseURL: URL) throws -> URL {
|
||||
guard MatrixEntityRegex.isMatrixEventIdentifier(eventIdentifier) else {
|
||||
throw PermalinkBuilderError.invalidEventIdentifier
|
||||
}
|
||||
@@ -121,7 +121,7 @@ enum PermalinkBuilder {
|
||||
throw PermalinkBuilderError.failedAddingPercentEncoding
|
||||
}
|
||||
|
||||
let urlString = "\(ServiceLocator.shared.settings.permalinkBaseURL)/#/\(roomId)/\(eventId)"
|
||||
let urlString = "\(baseURL)/#/\(roomId)/\(eventId)"
|
||||
|
||||
guard let url = URL(string: urlString) else {
|
||||
throw PermalinkBuilderError.failedConstructingURL
|
||||
@@ -132,12 +132,12 @@ enum PermalinkBuilder {
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private static func permalinkTo(roomIdentifierOrAlias: String) throws -> URL {
|
||||
private static func permalinkTo(roomIdentifierOrAlias: String, baseURL: URL) throws -> URL {
|
||||
guard let identifier = roomIdentifierOrAlias.addingPercentEncoding(withAllowedCharacters: uriComponentCharacterSet) else {
|
||||
throw PermalinkBuilderError.failedAddingPercentEncoding
|
||||
}
|
||||
|
||||
let urlString = "\(ServiceLocator.shared.settings.permalinkBaseURL)/#/\(identifier)"
|
||||
let urlString = "\(baseURL)/#/\(identifier)"
|
||||
|
||||
guard let url = URL(string: urlString) else {
|
||||
throw PermalinkBuilderError.failedConstructingURL
|
||||
|
||||
@@ -73,8 +73,10 @@ extension View {
|
||||
struct ShimmerOverlay_Previews: PreviewProvider {
|
||||
static let viewModel = HomeScreenViewModel(userSession: MockUserSession(clientProxy: MockClientProxy(userID: ""),
|
||||
mediaProvider: MockMediaProvider()),
|
||||
attributedStringBuilder: AttributedStringBuilder(),
|
||||
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher())
|
||||
attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: ServiceLocator.shared.settings.permalinkBaseURL),
|
||||
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
|
||||
appSettings: ServiceLocator.shared.settings,
|
||||
userIndicatorController: ServiceLocator.shared.userIndicatorController)
|
||||
|
||||
static var previews: some View {
|
||||
VStack {
|
||||
|
||||
@@ -22,7 +22,8 @@ struct MatrixUserShareLink<Label: View>: View {
|
||||
|
||||
init(userID: String, @ViewBuilder label: () -> Label) {
|
||||
self.label = label()
|
||||
permalink = try? PermalinkBuilder.permalinkTo(userIdentifier: userID)
|
||||
permalink = try? PermalinkBuilder.permalinkTo(userIdentifier: userID,
|
||||
baseURL: ServiceLocator.shared.settings.permalinkBaseURL)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
||||
Reference in New Issue
Block a user