From d80ac972171fdc779dfd226960a75f56c63fa9d5 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 14 Jun 2023 17:00:58 +1000 Subject: [PATCH] WIP: refactor BezierPathView with swiftUI --- Session.xcodeproj/project.pbxproj | 4 ++++ Session/Shared/BezierPathView.swift | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Session/Shared/BezierPathView.swift diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 79aac1997..c494e4665 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -157,6 +157,7 @@ 7BAF54D027ACCEEC003D12F8 /* EmptySearchResultCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BAF54CD27ACCEEC003D12F8 /* EmptySearchResultCell.swift */; }; 7BAF54D327ACCF01003D12F8 /* ShareAppExtensionContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BAF54D127ACCF01003D12F8 /* ShareAppExtensionContext.swift */; }; 7BAF54D427ACCF01003D12F8 /* SAEScreenLockViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BAF54D227ACCF01003D12F8 /* SAEScreenLockViewController.swift */; }; + 7BAFA1192A39669400B76CB9 /* BezierPathView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BAFA1182A39669400B76CB9 /* BezierPathView.swift */; }; 7BB92B3F28C825FD0082762F /* NewConversationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BB92B3E28C825FD0082762F /* NewConversationViewModel.swift */; }; 7BBBDC44286EAD2D00747E59 /* TappableLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BBBDC43286EAD2D00747E59 /* TappableLabel.swift */; }; 7BBBDC462875600700747E59 /* DocumentTitleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BBBDC452875600700747E59 /* DocumentTitleViewController.swift */; }; @@ -1281,6 +1282,7 @@ 7BAF54D127ACCF01003D12F8 /* ShareAppExtensionContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShareAppExtensionContext.swift; sourceTree = ""; }; 7BAF54D227ACCF01003D12F8 /* SAEScreenLockViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SAEScreenLockViewController.swift; sourceTree = ""; }; 7BAF54D527ACD0E2003D12F8 /* ReusableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReusableView.swift; sourceTree = ""; }; + 7BAFA1182A39669400B76CB9 /* BezierPathView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BezierPathView.swift; sourceTree = ""; }; 7BB92B3E28C825FD0082762F /* NewConversationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationViewModel.swift; sourceTree = ""; }; 7BBBDC43286EAD2D00747E59 /* TappableLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TappableLabel.swift; sourceTree = ""; }; 7BBBDC452875600700747E59 /* DocumentTitleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentTitleViewController.swift; sourceTree = ""; }; @@ -2698,6 +2700,7 @@ 4CA46F4B219CCC630038ABDE /* CaptionView.swift */, 34F308A01ECB469700BB7697 /* OWSBezierPathView.h */, 34F308A11ECB469700BB7697 /* OWSBezierPathView.m */, + 7BAFA1182A39669400B76CB9 /* BezierPathView.swift */, C354E75923FE2A7600CE22E3 /* BaseVC.swift */, B8BB82AA238F669C00BA5194 /* FullConversationCell.swift */, 4542DF53208D40AC007B4E76 /* LoadingViewController.swift */, @@ -6133,6 +6136,7 @@ 7B93D07727CF1A8A00811CB6 /* MockDataGenerator.swift in Sources */, 7B1B52D828580C6D006069F2 /* EmojiPickerSheet.swift in Sources */, FD368A6A29DE9E30000DBF1E /* UIContextualAction+Utilities.swift in Sources */, + 7BAFA1192A39669400B76CB9 /* BezierPathView.swift in Sources */, 7B4C75CD26BB92060000AC89 /* DeletedMessageView.swift in Sources */, FDD250722837234B00198BDA /* MediaGalleryNavigationController.swift in Sources */, FDD2506E283711D600198BDA /* DifferenceKit+Utilities.swift in Sources */, diff --git a/Session/Shared/BezierPathView.swift b/Session/Shared/BezierPathView.swift new file mode 100644 index 000000000..191b464f2 --- /dev/null +++ b/Session/Shared/BezierPathView.swift @@ -0,0 +1,21 @@ +// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved. + +import Foundation +import SwiftUI + +struct BezierPath: Shape { + let bezierPath: UIBezierPath + + func path(in rect: CGRect) -> Path { + let path = Path(bezierPath.cgPath) + + // Figure out how much bigger we need to make our path in order for it to fill the available space without clipping. + let multiplier = min(rect.width, rect.height) + + // Create an affine transform that uses the multiplier for both dimensions equally. + let transform = CGAffineTransform(scaleX: multiplier, y: multiplier) + + // Apply that scale and send back the result. + return path.applying(transform) + } +}