diff --git a/Example/Shared/ComponentsList.swift b/Example/Shared/ComponentsList.swift index 0c55b17..852ad7a 100644 --- a/Example/Shared/ComponentsList.swift +++ b/Example/Shared/ComponentsList.swift @@ -26,36 +26,36 @@ struct ComponentsList: View { Page(name: "Avatar", page: AnyView(AvatarDemo())), Page(name: "GridSelect", page: AnyView(GridSelectDemo())), Page(name: "TextField", page: AnyView(TextFieldDemo())), - //Page(name: "Icons", page: AnyView(IconsDemo())), + // Page(name: "Icons", page: AnyView(IconsDemo())), Page(name: "Row", page: AnyView(RowDemo())), Page(name: "SegmentedControl", page: AnyView(SegmentedControlDemo())), Page(name: "Select", page: AnyView(SelectDemo())), Page(name: "Surface", page: AnyView(SurfaceDemo())), - //Page(name: "Page", page: AnyView(PageDemo())), + // Page(name: "Page", page: AnyView(PageDemo())), ] var body: some View { #if os(iOS) - PageView("Example") { - ForEach(pages) { page in - HStack { - NavigationLink(page.name, destination: page.page) - .fontStyle(.button, color: .onSurfaceHighEmphasis) + PageView("Example") { + ForEach(pages) { page in + HStack { + NavigationLink(page.name, destination: page.page) + .fontStyle(.button, color: .onSurfaceHighEmphasis) - Spacer() + Spacer() + } + .padding() } - .padding() } - } - .leadingBar { - BarButton(type: .secondary("Settings", action: { isShowSetting.toggle() })) - } - .navigationable() - .sheet(isPresented: $isShowSetting) { - AppearanceSettingView() - } + .leadingBar { + BarButton(type: .secondary("Settings", action: { isShowSetting.toggle() })) + } + .navigationable() + .sheet(isPresented: $isShowSetting) { + AppearanceSettingView() + } #else - Text("Support will be in the future") + Text("Support will be in the future") #endif } } diff --git a/Example/Shared/DemoPages/IconsDemo.swift b/Example/Shared/DemoPages/IconsDemo.swift index f24e395..02131fd 100644 --- a/Example/Shared/DemoPages/IconsDemo.swift +++ b/Example/Shared/DemoPages/IconsDemo.swift @@ -7,30 +7,30 @@ import OversizeUI import SwiftUI #if os(iOS) -struct IconsDemo: View { - let grid = [GridItem(), - GridItem(), - GridItem(), - GridItem(), - GridItem(), - GridItem()] - var body: some View { - PageView("Icons") { - LazyVGrid(columns: grid) { - ForEach(IconsNames.allCases, id: \.self) { icon in - Icon(icon) - .padding(.vertical) + struct IconsDemo: View { + let grid = [GridItem(), + GridItem(), + GridItem(), + GridItem(), + GridItem(), + GridItem()] + var body: some View { + PageView("Icons") { + LazyVGrid(columns: grid) { + ForEach(IconsNames.allCases, id: \.self) { icon in + Icon(icon) + .padding(.vertical) + } } + .padding() } - .padding() + .modalable() } - .modalable() } -} -struct IconsDemo_Previews: PreviewProvider { - static var previews: some View { - IconsDemo() + struct IconsDemo_Previews: PreviewProvider { + static var previews: some View { + IconsDemo() + } } -} #endif diff --git a/Example/Shared/DemoPages/PageDemo.swift b/Example/Shared/DemoPages/PageDemo.swift index 0ec70fa..d149fce 100644 --- a/Example/Shared/DemoPages/PageDemo.swift +++ b/Example/Shared/DemoPages/PageDemo.swift @@ -7,52 +7,52 @@ import OversizeUI import SwiftUI #if os(iOS) -struct PageDemo: View { - @Environment(\.screenSize) var screenSize - @State var isShowModal = false + struct PageDemo: View { + @Environment(\.screenSize) var screenSize + @State var isShowModal = false - var body: some View { - PageView("Page view") { - VStack { - Button { - isShowModal = true - } label: { - Text("Show modal") - } + var body: some View { + PageView("Page view") { + VStack { + Button { + isShowModal = true + } label: { + Text("Show modal") + } - ForEach((1 ... 100).reversed(), id: \.self) { item in + ForEach((1 ... 100).reversed(), id: \.self) { item in - HStack { - Spacer() - Text("Item number \(item)") - Spacer() + HStack { + Spacer() + Text("Item number \(item)") + Spacer() + } + .padding() } - .padding() } } - } - .leadingBar { - BarButton(type: .back) - } - .trailingBar { - BarButton(type: .primary("Save", action: {})) - } - .topToolbar { - Text("Top") - } - .bottomToolbar { - Text("Bottom") - .padding(.bottom, screenSize.safeAreaBottom) - } - .sheet(isPresented: $isShowModal) { - IconsDemo() + .leadingBar { + BarButton(type: .back) + } + .trailingBar { + BarButton(type: .primary("Save", action: {})) + } + .topToolbar { + Text("Top") + } + .bottomToolbar { + Text("Bottom") + .padding(.bottom, screenSize.safeAreaBottom) + } + .sheet(isPresented: $isShowModal) { + IconsDemo() + } } } -} -struct PageDemo_Previews: PreviewProvider { - static var previews: some View { - PageDemo() + struct PageDemo_Previews: PreviewProvider { + static var previews: some View { + PageDemo() + } } -} #endif diff --git a/Example/Shared/DemoPages/TextFieldDemo.swift b/Example/Shared/DemoPages/TextFieldDemo.swift index 8bef8ff..2665e94 100644 --- a/Example/Shared/DemoPages/TextFieldDemo.swift +++ b/Example/Shared/DemoPages/TextFieldDemo.swift @@ -33,7 +33,7 @@ struct TextFieldDemo: View { }.padding() } - + .navigationTitle("Text fields") } } diff --git a/Sources/OversizeUI/Controls/LocationPicker/LocationPicker.swift b/Sources/OversizeUI/Controls/LocationPicker/LocationPicker.swift index b032f1a..338085e 100644 --- a/Sources/OversizeUI/Controls/LocationPicker/LocationPicker.swift +++ b/Sources/OversizeUI/Controls/LocationPicker/LocationPicker.swift @@ -3,6 +3,7 @@ // LocationPicker.swift // +import CoreLocation import MapKit import SwiftUI @@ -10,17 +11,20 @@ import SwiftUI public struct LocationPicker: View { @Environment(\.theme) private var theme: ThemeSettings + @Binding private var coordinates: CLLocationCoordinate2D + @Binding private var positionName: String? private let label: String + private let saveButtonText: String? - @Binding var coordinates: CLLocationCoordinate2D - @State var offset = CGPoint(x: 0, y: 0) + @State private var offset = CGPoint(x: 0, y: 0) @State private var showModal = false @State private var isSelected = false - public init(label: String, coordinates: Binding, saveButtonText: String? = nil) { + public init(label: String, coordinates: Binding, positionName: Binding, saveButtonText: String? = nil) { self.label = label self.saveButtonText = saveButtonText _coordinates = coordinates + _positionName = positionName } public var body: some View { @@ -32,8 +36,11 @@ import SwiftUI .fontStyle(.subtitle1, color: .onSurfaceHighEmphasis) } Spacer() - Text(String(coordinates.latitude)) - Text(String(coordinates.longitude)) + + if let positionName = positionName { + Text(positionName) + .fontStyle(.subtitle2, color: .onSurfaceMediumEmphasis) + } Icon(.chevronDown, color: .onSurfaceHighEmphasis) } @@ -51,10 +58,12 @@ import SwiftUI : Color.surfaceSecondary, lineWidth: CGFloat(theme.borderSize)) ) ) - .sheet(isPresented: $showModal) { modal } + .onChange(of: coordinates) { + updateCityName(coordinate: $0) + } } public var modal: some View { @@ -66,8 +75,18 @@ import SwiftUI Spacer() MaterialSurface { - Text("\(coordinates.latitude), \(coordinates.longitude)") + VStack(alignment: .center, spacing: .xxSmall) { + if let positionName = positionName { + Text(positionName) + .fontStyle(.title3, color: .onSurfaceHighEmphasis) + } + Text("\(coordinates.latitude), \(coordinates.longitude)") + .fontStyle(.subtitle2, color: .onSurfaceMediumEmphasis) + } } + .controlPadding(.small) + .controlRadius(.large) + .multilineTextAlignment(.center) }.padding() } @@ -80,5 +99,34 @@ import SwiftUI })) } } + + private func updateCityName(coordinate: CLLocationCoordinate2D) { + let loc = CLLocation( + latitude: coordinate.latitude, + longitude: coordinate.longitude + ) + + let geocoder = CLGeocoder() + + geocoder.reverseGeocodeLocation(loc) { placemarks, error in + if error != nil { return } + if let firstLocation = placemarks?.first as? CLPlacemark { + if let locality = firstLocation.locality { + self.positionName = locality + + } else if let subLocality = firstLocation.subLocality { + self.positionName = subLocality + } else { + self.positionName = firstLocation.name + } + } + } + } + } + + extension CLLocationCoordinate2D: Equatable {} + + public func == (lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool { + lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude } #endif diff --git a/Sources/OversizeUI/Controls/Row/Row.swift b/Sources/OversizeUI/Controls/Row/Row.swift index 41a2ccb..801d159 100644 --- a/Sources/OversizeUI/Controls/Row/Row.swift +++ b/Sources/OversizeUI/Controls/Row/Row.swift @@ -24,6 +24,7 @@ public enum RowLeadingType { case image(_ image: Image) case systemImage(_ imageName: String) case avatar(_ avatar: AvatarView) + case view(_ view: AnyView) } public struct Row: View { @@ -169,6 +170,8 @@ public struct Row: View { .font(.system(size: 24)) .frame(width: 24, height: 24, alignment: .center) .padding(.trailing, Constants.spacingIconAndText) + case let .view(view): + view } } diff --git a/Sources/OversizeUI/Extensions/EnvironmentKey/ControlSizeEnvironment.swift b/Sources/OversizeUI/Extensions/EnvironmentKey/ControlSizeEnvironment.swift index 99ae3e2..e53c649 100644 --- a/Sources/OversizeUI/Extensions/EnvironmentKey/ControlSizeEnvironment.swift +++ b/Sources/OversizeUI/Extensions/EnvironmentKey/ControlSizeEnvironment.swift @@ -3,30 +3,30 @@ // ControlSizeEnvironment.swift // -//import SwiftUI +// import SwiftUI // -//public enum ControlSize { +// public enum ControlSize { // case mini // case small // case regular // @available(macOS 11.0, *) // case large -//} +// } // -//private struct ControlSizeKey: EnvironmentKey { +// private struct ControlSizeKey: EnvironmentKey { // public static var defaultValue: ControlSize = .regular -//} +// } // -//public extension EnvironmentValues { +// public extension EnvironmentValues { // var controlSize: ControlSize { // get { self[ControlSizeKey.self] } // set { self[ControlSizeKey.self] = newValue } // } -//} +// } // -//public extension View { +// public extension View { // @_disfavoredOverload // @inlinable func controlSize(_ controlSize: ControlSize) -> some View { // environment(\.controlSize, controlSize) // } -//} +// }