VComponents
Table of Contents
Description
VComponents is a SwiftUI
package that contains 30+ customizable UI components.
Components
Buttons
State Pickers
Item Pickers
Value Pickers
Inputs
Containers
Lists
Modals
Messages
Indicators
Misc
Guidelines
UI Models
Components are not meant to be customized like you would a native SwiftUI
component.
Instead, UI model can be passed as parameter to initializers. This parameter has default value, and is not required every time you create a view.
UI Models are struct
s with default values. They break down into 5 models: Layout
, Colors
, Fonts
, Animations
, and Misc
.
For instance, changing foreground color of VPlainButton
can be done by passing an IU model.
Not Preferred:
var body: some View {
VPlainButton(
action: doSomething,
title: "Lorem ipsum"
)
.foregroundColor(.black)
}
Preferred:
let uiModel: VPlainButtonUIModel = {
var UIModel: VPlainButtonUIModel = .init()
uiModel.colors.title = VPlainButtonUIModel.Colors.StateColors(
enabled: .black,
pressed: .gray,
disabled: .gray
)
return uiModel
}()
var body: some View {
VPlainButton(
uiModel: uiModel,
action: doSomething,
title: "Lorem ipsum"
)
}
Alternately, you can create static instances of UI models for reusability.
extension VPlainButtonUIModel {
static let someUIModel: VPlainButtonUIModel = {
var uiModel: VPlainButtonUIModel = .init()
uiModel.colors.title = VPlainButtonUIModel.Colors.StateColors(
enabled: .black,
pressed: .gray,
disabled: .gray
)
return uiModel
}()
}
var body: some View {
VPlainButton(
uiModel: .someUIModel,
action: doSomething,
title: "Lorem ipsum"
)
}
Animations
VComponents approaches animations as bound to components and their UI models, and not to state. Which means, that to modify a state of component with an animation, you need to pass a custom UI model.
For instance, by default, VToggle
uses easeIn
animation with duration 0.1
to state change. This applies to both toggle press, as well as external modification of state:
@State private var isOn: Bool = false
var body: some View {
VStack(content: {
VToggle(isOn: $isOn)
VPlainButton(
action: { isOn.toggle() },
title: "Toggle"
)
})
}
If you wish to completely cancel animations, you have two options. First, is to set stateChange
animation to nil
, which still applies a nil
animation. Second, is to set appliesStateChangeAnimation
to false
, which doesn't apply stateChange
animation at all.
@State private var isOn: Bool = false
var body: some View {
VStack(content: {
VToggle(
uiModel: {
var uiModel: VToggleUIModel = .init()
uiModel.animations.stateChange = nil
return uiModel
}(),
isOn: $isOn
)
VPlainButton(
action: { isOn.toggle() },
title: "Toggle"
)
})
}
or
@State private var isOn: Bool = false
var body: some View {
VStack(content: {
VToggle(
uiModel: {
var uiModel: VToggleUIModel = .init()
uiModel.animations.appliesStateChangeAnimation = false
return uiModel
}(),
isOn: $isOn
)
VPlainButton(
action: { isOn.toggle() },
title: "Toggle"
)
})
}
In some cases, the difference between these two may be significant. For instance, we can set the flag to false
, and mutate state with an external animation:
@State private var isOn: Bool = false
var body: some View {
VStack(content: {
VToggle(
uiModel: {
var uiModel: VToggleUIModel = .init()
uiModel.animations.appliesStateChangeAnimation = false
return uiModel
}(),
isOn: $isOn
)
VPlainButton(
action: {
withAnimation(.linear(duration: 1), {
isOn.toggle()
})
},
title: "Toggle"
)
})
}
Installation
Swift Package Manager
Add https://github.com/VakhoKontridze/VComponents
as a Swift Package in Xcode and follow the instructions.
Compatibility
Package provides limited macOS
, tvOS
, and watchOS
support.
Versions with different majors are not directly compatible. When a new major is released, deprecated symbols are removed.
Versioning
Major. Major changes, such as big overhauls
Minor. Minor changes, such as new component, types, or properties in UI models
Patch. Bug fixes and improvements
History
Ver | Release Date | Swift | SDK | VCore | Comment |
---|---|---|---|---|---|
4.0 (4.0.0 - 4.x.x) |
2023 04 09 | 5.8 |
iOS 13.0 macOS 10.15 tvOS 13.0 watchOS 6.0 |
4.7.0 - 4.x.x |
iOS 13.0 support. Multiplatform support. RTL language support. |
3.0 (3.0.0 - 3.2.3) |
2022 10 02 | 5.7 | iOS 16.0 | 4.1.0 - 4.x.x |
New SwiftUI API. API changes. |
2.0 (2.0.0 - 2.3.4) |
2022 05 26 | 5.6 | iOS 15.0 | 3.2.0 - 3.x.x |
New SwiftUI API. API changes. SPM support. |
1.0 (1.0.0 - 1.6.0) |
2021 02 07 | 5.3 | iOS 14.0 | - | - |
Contact
e-mail: vakho.kontridze@gmail.com