diff --git a/Sources/MUDKit/Extensions/Log+Ext.swift b/Sources/MUDKit/Extensions/Internal/Log+Ext.swift similarity index 100% rename from Sources/MUDKit/Extensions/Log+Ext.swift rename to Sources/MUDKit/Extensions/Internal/Log+Ext.swift diff --git a/Sources/MUDKit/Extensions/View+Ext.swift b/Sources/MUDKit/Extensions/Internal/View+Ext.swift similarity index 100% rename from Sources/MUDKit/Extensions/View+Ext.swift rename to Sources/MUDKit/Extensions/Internal/View+Ext.swift diff --git a/Sources/MUDKit/Extensions/Public/View+FrameGeometry.swift b/Sources/MUDKit/Extensions/Public/View+FrameGeometry.swift new file mode 100644 index 0000000..e198337 --- /dev/null +++ b/Sources/MUDKit/Extensions/Public/View+FrameGeometry.swift @@ -0,0 +1,7 @@ +import SwiftUI + +public extension View { + func frameGeometry(_ color: Color = .red) -> some View { + modifier(FrameGeometry(color: color)) + } +} diff --git a/Sources/MUDKit/Key/Key.swift b/Sources/MUDKit/Key/Key.swift index 3476290..b998145 100644 --- a/Sources/MUDKit/Key/Key.swift +++ b/Sources/MUDKit/Key/Key.swift @@ -2,4 +2,5 @@ enum Key: String { case isOverrideBaseConfig case featureToggles + case frameGeometry } diff --git a/Sources/MUDKit/Models/Internal/FrameGeometry.swift b/Sources/MUDKit/Models/Internal/FrameGeometry.swift new file mode 100644 index 0000000..d46a571 --- /dev/null +++ b/Sources/MUDKit/Models/Internal/FrameGeometry.swift @@ -0,0 +1,45 @@ +import SwiftUI + +struct FrameGeometry: ViewModifier { + let color: Color + + func body(content: Content) -> some View { + if UserDefaultsService.get(for: Key.frameGeometry.rawValue) == true { + content + .overlay(GeometryReader(content: overlayContent)) + } else { + content + } + } + + private func overlayContent(for geometry: GeometryProxy) -> some View { + ZStack(alignment: .topTrailing) { + Rectangle() + .strokeBorder(style: StrokeStyle(lineWidth: 1, dash: [5])) + .foregroundColor(color) + Text(describe(geometry)) + .font(.caption2) + .foregroundColor(color) + .padding(2) + } + } + + private func describe(_ geometry: GeometryProxy) -> String { + var information: [String] = [] + let size = "\(Int(geometry.size.width))x\(Int(geometry.size.height))" + information.append(size) + + if geometry.safeAreaInsets != EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0 ) { + let safeAreaInsets = [ + geometry.safeAreaInsets.top, + geometry.safeAreaInsets.leading, + geometry.safeAreaInsets.trailing, + geometry.safeAreaInsets.bottom + ].map { "\(Int($0))" }.joined(separator: ";") + + information.append("[\(safeAreaInsets)]") + } + + return information.joined(separator: " ") + } +} diff --git a/Sources/MUDKit/Models/FeatureToggle.swift b/Sources/MUDKit/Models/Public/FeatureToggle.swift similarity index 100% rename from Sources/MUDKit/Models/FeatureToggle.swift rename to Sources/MUDKit/Models/Public/FeatureToggle.swift diff --git a/Sources/MUDKit/UI/FrameGeometry/FrameGeometryView.swift b/Sources/MUDKit/UI/FrameGeometry/FrameGeometryView.swift new file mode 100644 index 0000000..6a5523f --- /dev/null +++ b/Sources/MUDKit/UI/FrameGeometry/FrameGeometryView.swift @@ -0,0 +1,16 @@ +import SwiftUI + +struct FrameGeometryView: View { + @State private var isEnabled: Bool = UserDefaultsService.get(for: Key.frameGeometry.rawValue) ?? false + + var body: some View { + Toggle("Frame geometry", isOn: $isEnabled) + .onChange(of: isEnabled) { newValue in + UserDefaultsService.set(value: newValue, for: Key.frameGeometry.rawValue) + } + } +} + +#Preview { + FrameGeometryView() +} diff --git a/Sources/MUDKit/UI/MUDKitView.swift b/Sources/MUDKit/UI/MUDKitView.swift index 5be1048..15d1890 100644 --- a/Sources/MUDKit/UI/MUDKitView.swift +++ b/Sources/MUDKit/UI/MUDKitView.swift @@ -27,6 +27,7 @@ public struct MUDKitView: View { NavigationLink("Deeplink") { DeeplinkView() } + FrameGeometryView() } if hasCustomContent { Section("Custom") { diff --git a/Sources/MUDKit/UI/Storage/StorageView.swift b/Sources/MUDKit/UI/Storage/StorageView.swift index b47841b..1caead4 100644 --- a/Sources/MUDKit/UI/Storage/StorageView.swift +++ b/Sources/MUDKit/UI/Storage/StorageView.swift @@ -71,7 +71,7 @@ struct StorageView: View { .background(Color.white) .navigationTitle(type.title) .resignResponderOnTap() - .alert("Are you shure?", isPresented: $isAlertShown) { + .alert("Are you sure?", isPresented: $isAlertShown) { Button("Yes", role: .destructive) { if key.isEmpty { type.clear()