Skip to content

Commit

Permalink
Refactor dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
matgentili committed Feb 10, 2023
1 parent 30f54a1 commit 141e2db
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 51 deletions.
20 changes: 10 additions & 10 deletions Sources/SirioKitIOS/Component/Dialog/View/Dialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public struct Dialog: View {
var actionSecondButton: (() -> Void)?

// Action
var onTapInfo: (() -> Void)?
var onTapClose: (() -> Void)?
var onTapInfoAction: (() -> Void)?
var onTapCloseAction: (() -> Void)?

var isVisibleInfoIcon: Bool

Expand All @@ -63,8 +63,8 @@ public struct Dialog: View {
actionFirstButton: (() -> Void)?,
textSecondButton: String?,
actionSecondButton: (() -> Void)?,
onTapInfo: (() -> Void)?,
onTapClose: (() -> Void)?,
onTapInfoAction: (() -> Void)?,
onTapCloseAction: (() -> Void)?,
isVisibleInfoIcon: Bool){
self.type = type
self.isVisibleInfoIcon = isVisibleInfoIcon
Expand All @@ -76,8 +76,8 @@ public struct Dialog: View {
self.actionFirstButton = actionFirstButton
self.textSecondButton = textSecondButton
self.actionSecondButton = actionSecondButton
self.onTapInfo = onTapInfo
self.onTapClose = onTapClose
self.onTapInfoAction = onTapInfoAction
self.onTapCloseAction = onTapCloseAction
}

private var iconColor: Color {
Expand Down Expand Up @@ -121,13 +121,13 @@ public struct Dialog: View {
HStack { // Close
Spacer()
ButtonIconOnly(style: .ghost, size: .large, icon: .times, action: {
onTapClose?()
onTapCloseAction?()
})
}
if let icon = icon, isVisibleInfoIcon {
HStack(spacing: Size.Dialog.noSpacing){
Button(action: {
onTapInfo?()
onTapInfoAction?()

}, label: {
SirioIcon(icon: icon)
Expand Down Expand Up @@ -242,8 +242,8 @@ struct Dialog_Previews: PreviewProvider {
actionFirstButton: nil,
textSecondButton: "Text",
actionSecondButton: nil,
onTapInfo: nil,
onTapClose: nil,
onTapInfoAction: nil,
onTapCloseAction: nil,
isVisibleInfoIcon: true)
}
}
4 changes: 2 additions & 2 deletions Sources/SirioKitIOS/Extension/Color+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ extension Color {

struct Text {
static let dark = StyleDictionaryColor.aliasTextColorPrimaryLight0.color
static let light = StyleDictionaryColor.aliasTextColorPrimaryDark110.color // dovrebbe essere 0 ma non c'è
static let light = StyleDictionaryColor.aliasTextColorPrimaryDark110.color
static let disabled = StyleDictionaryColor.aliasTextColorDisabled.color
}

struct Icon {
static let dark = StyleDictionaryColor.aliasTextColorPrimaryLight0.color
static let light = StyleDictionaryColor.aliasTextColorPrimaryDark110.color // dovrebbe essere 0 ma non c'è
static let light = StyleDictionaryColor.aliasTextColorPrimaryDark110.color
static let disabled = StyleDictionaryColor.aliasTextColorDisabled.color
}
}
Expand Down
27 changes: 14 additions & 13 deletions Sources/SirioKitIOS/Extension/View+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,20 @@ public extension View {
onTapInfoAction: (() -> Void)? = nil,
onTapCloseAction: (() -> Void)? = nil,
isVisibleInfoIcon: Bool = true) -> some View {
return modifier(DialogModifier(isPresented: isPresented,
type: type,
title: title,
subtitle: subtitle,
textfield1: textfield1,
textfield2: textfield2,
textFirstButton: textFirstButton,
actionFirstButton: actionFirstButton,
textSecondButton: textSecondButton,
actionSecondButton: actionSecondButton,
onTapInfoAction: onTapInfoAction,
onTapCloseAction: onTapCloseAction,
isVisibleInfoIcon: isVisibleInfoIcon))
return modifier(ClearModifier(isPresented: isPresented, fullScreenContent: {
Dialog(type: type,
title: title,
subtitle: subtitle,
textfield1: textfield1,
textfield2: textfield2,
textFirstButton: textFirstButton,
actionFirstButton: actionFirstButton,
textSecondButton: textSecondButton,
actionSecondButton: actionSecondButton,
onTapInfoAction: onTapInfoAction,
onTapCloseAction: onTapCloseAction,
isVisibleInfoIcon: isVisibleInfoIcon)
}))
}
}

Expand Down
62 changes: 62 additions & 0 deletions Sources/SirioKitIOS/Modifier/ClearModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// ClearModifier.swift
//
// SPDX-FileCopyrightText: 2022 Istituto Nazionale Previdenza Sociale
//
// SPDX-License-Identifier: BSD-3-Clause
//


import SwiftUI
import UIKit

public struct ClearModifier<FullScreenContent: View>: ViewModifier {

@Binding var isPresented: Bool
let fullScreenContent: () -> (FullScreenContent)

public func body(content: Content) -> some View {
content
.onChange(of: isPresented) { _ in
UIView.setAnimationsEnabled(false)
}
.fullScreenCover(isPresented: $isPresented,
content: {
ZStack {
fullScreenContent()
}
.edgesIgnoringSafeArea(.all)
.background(ClearBackgroundView())
.onAppear {
if !UIView.areAnimationsEnabled {
UIView.setAnimationsEnabled(true)
}
}
.onDisappear {
if !UIView.areAnimationsEnabled {
UIView.setAnimationsEnabled(true)
}
}
})
}

}


private struct ClearBackgroundView: UIViewRepresentable {

private class ClearView: UIView {

override func didMoveToWindow() {
super.didMoveToWindow()
superview?.superview?.backgroundColor = .clear
}
}

func makeUIView(context: Context) -> UIView {
return ClearView()
}

func updateUIView(_ uiView: UIView, context: Context) {}

}
131 changes: 105 additions & 26 deletions iOS-Example/iOS-Example/ViewExample/ExampleDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,31 +90,44 @@ struct ExampleDialog_Previews: PreviewProvider {

struct Dialog1: View {
@Environment(\.presentationMode) var mode: Binding<PresentationMode>
@State var isPresented: Bool = true
@State var isPresented: Bool = false

var body: some View {
VStack {

}.dialog(isPresented: $isPresented,
type: .default,
title: "Titolo finestra di dialogo",
subtitle: .loremIpsum,
textfield1: .init(type: .info, label: "Label", placeholder: "Placeholder", text: ""),
textfield2: .init(type: .info, label: "Label", placeholder: "Placeholder", text: ""),
textFirstButton: "Text",
actionFirstButton: nil,
textSecondButton: "Text",
actionSecondButton: nil,
onTapInfoAction: nil,
onTapCloseAction: {self.mode.wrappedValue.dismiss()},
isVisibleInfoIcon: true)
}
.dialog(isPresented: $isPresented,
type: .default,
title: "Titolo finestra di dialogo",
subtitle: .loremIpsum,
textfield1: .init(type: .info, label: "Label", placeholder: "Placeholder", text: ""),
textfield2: .init(type: .info, label: "Label", placeholder: "Placeholder", text: ""),
textFirstButton: "Text",
actionFirstButton: nil,
textSecondButton: "Text",
actionSecondButton: nil,
onTapInfoAction: nil,
onTapCloseAction: {
self.isPresented = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.mode.wrappedValue.dismiss()
})
},
isVisibleInfoIcon: true)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.isPresented = true
})
}
}
}




struct Dialog2: View {
@Environment(\.presentationMode) var mode: Binding<PresentationMode>
@State var isPresented: Bool = true
@State var isPresented: Bool = false

var body: some View {
VStack {
Expand All @@ -130,14 +143,25 @@ struct Dialog2: View {
textSecondButton: "Text",
actionSecondButton: nil,
onTapInfoAction: nil,
onTapCloseAction: {self.mode.wrappedValue.dismiss()},
onTapCloseAction: {
self.isPresented = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.mode.wrappedValue.dismiss()
})
},
isVisibleInfoIcon: true)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.isPresented = true
})
}
}

}

struct Dialog3: View {
@Environment(\.presentationMode) var mode: Binding<PresentationMode>
@State var isPresented: Bool = true
@State var isPresented: Bool = false

var body: some View {
VStack {
Expand All @@ -153,15 +177,26 @@ struct Dialog3: View {
textSecondButton: "Text",
actionSecondButton: nil,
onTapInfoAction: nil,
onTapCloseAction: {self.mode.wrappedValue.dismiss()},
onTapCloseAction: {
self.isPresented = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.mode.wrappedValue.dismiss()
})
},
isVisibleInfoIcon: true)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.isPresented = true
})
}

}
}


struct Dialog4: View {
@Environment(\.presentationMode) var mode: Binding<PresentationMode>
@State var isPresented: Bool = true
@State var isPresented: Bool = false

var body: some View {
VStack {
Expand All @@ -177,14 +212,25 @@ struct Dialog4: View {
textSecondButton: "Text",
actionSecondButton: nil,
onTapInfoAction: nil,
onTapCloseAction: {self.mode.wrappedValue.dismiss()},
onTapCloseAction: {
self.isPresented = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.mode.wrappedValue.dismiss()
})
},
isVisibleInfoIcon: true)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.isPresented = true
})
}

}
}

struct Dialog5: View {
@Environment(\.presentationMode) var mode: Binding<PresentationMode>
@State var isPresented: Bool = true
@State var isPresented: Bool = false

var body: some View {
VStack {
Expand All @@ -200,14 +246,25 @@ struct Dialog5: View {
textSecondButton: nil,
actionSecondButton: nil,
onTapInfoAction: nil,
onTapCloseAction: {self.mode.wrappedValue.dismiss()},
onTapCloseAction: {
self.isPresented = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.mode.wrappedValue.dismiss()
})
},
isVisibleInfoIcon: true)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.isPresented = true
})
}

}
}

struct DialogAlert: View {
@Environment(\.presentationMode) var mode: Binding<PresentationMode>
@State var isPresented: Bool = true
@State var isPresented: Bool = false

var body: some View {
VStack {
Expand All @@ -223,14 +280,25 @@ struct DialogAlert: View {
textSecondButton: "Text",
actionSecondButton: nil,
onTapInfoAction: nil,
onTapCloseAction: {self.mode.wrappedValue.dismiss()},
onTapCloseAction: {
self.isPresented = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.mode.wrappedValue.dismiss()
})
},
isVisibleInfoIcon: true)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.isPresented = true
})
}

}
}

struct DialogWarning: View {
@Environment(\.presentationMode) var mode: Binding<PresentationMode>
@State var isPresented: Bool = true
@State var isPresented: Bool = false

var body: some View {
VStack {
Expand All @@ -246,7 +314,18 @@ struct DialogWarning: View {
textSecondButton: "Text",
actionSecondButton: nil,
onTapInfoAction: nil,
onTapCloseAction: {self.mode.wrappedValue.dismiss()},
onTapCloseAction: {
self.isPresented = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.mode.wrappedValue.dismiss()
})
},
isVisibleInfoIcon: true)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.isPresented = true
})
}

}
}

0 comments on commit 141e2db

Please sign in to comment.