SwiftUI package for displaying custom iOS 13 like modal.
It supports:
Requirements: iOS 13 or later, Xcode 11 or later.
Simplest way to install is to use Swift Package Manager.
In Xcode go to File -> Swift Packages -> Add Package Dependency
and paste in the repo's url: https://github.com/ViktorMaric/HalfModal
Import HalfModal to your project: import HalfModal
You can put any content you want inside a modal.
HalfModal example:
ZStack {
Button(action: {
withAnimation {
self.showingHalfModal = true
}
}, label: {
Text("Show HalfModalView")
})
if showingHalfModal {
HalfModalView(content: AnyView(Text("content")), header: AnyView(Text("Header")), isPresented: $showingHalfModal)
}
}
Pass HalfModalContent() View to the content parameter to get iOS 13 like buttons.
ZStack {
Button(action: {
withAnimation {
self.showingHalfModal = true
}
}, label: {
Text("Show HalfModalView")
})
if showingHalfModal {
HalfModalView(content: AnyView(HalfModalContent(priorButtons: [AnyView(
Button(action: {
withAnimation {
self.showingHalfModal = false
}
}, label: {
ModalButtonView(title: "Copy", image: Image(systemName: "doc.on.doc"), labelColor: .primary)
})),
AnyView(Button(action: {
withAnimation {
self.showingHalfModal = false
}
}, label: {
ModalButtonView(title: "Share", image: Image(systemName: "square.and.arrow.up"), labelColor: .primary)
}))
], secondaryButtons: [
AnyView(Button(action: {
withAnimation {
self.showingHalfModal = false
}
}, label: {
ModalButtonView(title: "Information", image: Image(systemName: "info.circle"), labelColor: .primary)
})),
AnyView(Button(action: {
withAnimation {
self.showingHalfModal = false
}
}, label: {
ModalButtonView(title: "Love", image: Image(systemName: "heart"), labelColor: .primary)
})),
AnyView(Button(action: {
withAnimation {
self.showingHalfModal = false
}
}, label: {
ModalButtonView(title: "Dislike", image: Image(systemName: "hand.thumbsdown"), labelColor: .primary)
}))])), header: AnyView(Text("Header")), isPresented: self.$showingHalfModal)
}
}
Best practice:
Show the most frequently used buttons at the top.
Avoid using filled shapes.