CleanUI is a collection of Swift and SwiftUI helpers. CleanUI views have a CL
prefix. CleanUI helper classes have a CU
prefix. CleanUI is ripped out of the Knoggl iOS App to make a reusable framework, which can be worked on without directly changing things inside of the Knoggl iOS App.
The following list of examples is just a small list to show what CleanUI can do.
import CleanUI
CleanUI has some really cool helper classes.
// Shows an alert with the given SwiftUI.View
CUAlert.show(YOUR_SWIFTUI_VIEW)
// Clears all alerts
CUAlert.clearAll()
// Shows an sheet with the given SwiftUI.View
CUSheet.show(YOUR_SWIFTUI_VIEW)
// Clears all sheets
CUSheet.clearAll()
// Shows an alert message with the given title, subTitle and type
CUAlertMessage.show(_ title: String, subTitle: String = "", type: CLInfoCard.InfoCardType = .info)
CUNavigation does its best to find the current UINavigationView inside the view hierarchy and gives you some basic functionality which are still missing in SwiftUI.
// Try's to pop to the rootViewController / View inside of the current UINavigationController
CUNavigation.popToRootView()
// Try's to pop the current view to navigate one step back
CUNavigation.pop()
// Try's to push to a SwiftUI View inside the current UINavigationController
CUNavigation.pushToSwiftUiView(YOUR_SWIFTUI_VIEW)
Some of CleanUI's views
Perfect sized icons with more functionality.
// A small icon
CLIcon(systemImage: "clock", size: .small)
// An icon with a newBadge and trailing offset
CLIcon(systemImage: "clock", newBadge: true, offset: .trailing(16))
// A tappable icon with newBadge
CLIcon(systemImage: "clock", newBadge: true) {
CUAlertMessage.show("Tapped")
}
Richtext with optional link, hashtag and mention detection and tap actions.
let text = "Hello @CleanUI! I love #Knoggl. Go visit www.knoggl.com"
// All attributes
CLRichText(text, attributes: [
.links(onTapAction: { linkString in
// Open link in CUBrowser
CUBrowser.open(linkString)
}),
.hashtags(onTapAction: { hashtag in
// Push to hashtags page?
CUNavigation.pushToSwiftUiView(YOUR_SWIFTUI_VIEW)
}),
.mentions(onTapAction: { mention in
// Push to profile?
CUNavigation.pushToSwiftUiView(YOUR_SWIFTUI_VIEW)
}),
])
// Only links
CLRichText(text, attributes: [
.links(onTapAction: { linkString in
// Open link in CUBrowser
CUBrowser.open(linkString)
}),
])
With CLScrollView you can track the current scroll offset.
CLScrollView(offsetChanged: {
print("Offset has changed: \($0.y)")
}) {
VStack {
Text("Hello CleanUI! Hello Knoggl!")
Text("Hello CleanUI! Hello Knoggl!")
Text("Hello CleanUI! Hello Knoggl!")
Text("Hello CleanUI! Hello Knoggl!")
Text("Hello CleanUI! Hello Knoggl!")
}
}
CLDateTime gives you a human readable represantation of a ISO8601
date string.
// Without T seperator
CLDateTime("2022-05-11 00:54:06")
// With T seperator
CLDateTime("2022-06-11T10:56:45")
CLUrlImage downloads the given image and displays it.
CLUrlImage("MY_IMAGE_URL_STRING")
// You can set a fallback image
CLUrlImage("MY_IMAGE_URL_STRING", fallbackImage: MY_UIIMAGE)
CleanUI has some pretty cool SwiftUI modifiers.
The OnLoad modifier is pretty much the same as .onAppear with the difference, that .onLoad is called only once.
MyView()
.onLoad {
// Gets called only on the first onAppear
print("Hallo, Welt!")
}
OnRotate fires everytime the device rotates and returns the current UIDeviceOrientation
.
MyView()
.onRotate { rotation in
// Do something with the rotation
}
The PinchToZoom modifier allows pinching the view its attached to.
MyView()
.pinchToZoom()
There is so much more in CleanUI. Just browse through the project to find everything CleanUI has to offer. Feel free to contribute!