-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
382a658
commit 8ff68eb
Showing
14 changed files
with
175 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// EmergeModifierFinder.swift | ||
// | ||
// | ||
// Created by Noah Martin on 10/6/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import SnapshotPreviewsCore | ||
|
||
// Classes in this file get compiled to an app that use any of the custom preview preferences. | ||
// The inserted test runner code finds these classes through ObjC runtime functions (NSClassFromString) | ||
// and Swift reflection (Mirror). | ||
|
||
@objc(EmergeModifierState) | ||
class EmergeModifierState: NSObject { | ||
|
||
@objc | ||
static let shared = EmergeModifierState() | ||
|
||
func reset() { | ||
expansionPreference = nil | ||
renderingMode = nil | ||
precision = nil | ||
} | ||
|
||
var expansionPreference: Bool? | ||
var renderingMode: EmergeRenderingMode.RawValue? | ||
var precision: Float? | ||
} | ||
|
||
@objc(EmergeModifierFinder) | ||
class EmergeModifierFinder: NSObject { | ||
let finder: (any View) -> (any View) = { view in | ||
EmergeModifierState.shared.reset() | ||
return view | ||
.onPreferenceChange(ExpansionPreferenceKey.self, perform: { value in | ||
EmergeModifierState.shared.expansionPreference = value | ||
}) | ||
.onPreferenceChange(RenderingModePreferenceKey.self, perform: { value in | ||
EmergeModifierState.shared.renderingMode = value | ||
}) | ||
.onPreferenceChange(PrecisionPreferenceKey.self, perform: { value in | ||
EmergeModifierState.shared.precision = value | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// ExpansionPreference.swift | ||
// | ||
// | ||
// Created by Noah Martin on 9/7/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct ExpansionPreferenceKey: PreferenceKey { | ||
static func reduce(value: inout Bool?, nextValue: () -> Bool?) { | ||
if value == nil { | ||
value = nextValue() | ||
} | ||
} | ||
|
||
static var defaultValue: Bool? = nil | ||
} | ||
|
||
extension View { | ||
public func emergeExpansion(_ enabled: Bool?) -> some View { | ||
preference(key: ExpansionPreferenceKey.self, value: enabled) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// PrecisionPreference.swift | ||
// | ||
// | ||
// Created by Noah Martin on 9/5/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct PrecisionPreferenceKey: PreferenceKey { | ||
static func reduce(value: inout Float?, nextValue: () -> Float?) { | ||
value = nextValue() | ||
} | ||
|
||
static var defaultValue: Float? = nil | ||
} | ||
|
||
extension View { | ||
public func emergeSnapshotPrecision(_ precision: Float?) -> some View { | ||
preference(key: PrecisionPreferenceKey.self, value: precision) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// RenderingModePreference.swift | ||
// | ||
// | ||
// Created by Noah Martin on 9/7/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import SnapshotPreviewsCore | ||
|
||
struct RenderingModePreferenceKey: PreferenceKey { | ||
static func reduce(value: inout Int?, nextValue: () -> Int?) { | ||
value = nextValue() | ||
} | ||
|
||
static var defaultValue: EmergeRenderingMode.RawValue? = nil | ||
} | ||
|
||
extension View { | ||
public func emergeRenderingMode(_ renderingMode: EmergeRenderingMode?) -> some View { | ||
preference(key: RenderingModePreferenceKey.self, value: renderingMode?.rawValue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// EmergeRenderingMode.swift | ||
// | ||
// | ||
// Created by Noah Martin on 10/6/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum EmergeRenderingMode: Int { | ||
// Renders using CALayer render(in:) | ||
case coreAnimation | ||
// Renders using UIView drawHierarchy(in: , afterScreenUpdates: true) | ||
case uiView | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters