-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Support local appearance configuration #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -142,8 +142,9 @@ public class InputFieldView: UIView { | |||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/// Appearance can be set globally using `configureAppearance()` by modifying the `defaultAppearance`, | ||||||||||||||||||||||
/// or locally by sending an appearance in `setup(with: Model, customAppearance: InputFieldAppearance?)`. | ||||||||||||||||||||||
open var standardAppearance: InputFieldAppearance = defaultAppearance | ||||||||||||||||||||||
|
||||||||||||||||||||||
public static var defaultAppearance: InputFieldAppearance = .default | ||||||||||||||||||||||
|
||||||||||||||||||||||
// MARK: - Combine | ||||||||||||||||||||||
|
@@ -563,7 +564,12 @@ public extension InputFieldView { | |||||||||||||||||||||
|
||||||||||||||||||||||
var isSelected: Bool { textField.isSelected } | ||||||||||||||||||||||
|
||||||||||||||||||||||
func setup(with model: Model) { | ||||||||||||||||||||||
func setup(with model: Model, customAppearance: InputFieldAppearance? = nil) { | ||||||||||||||||||||||
if let customAppearance { | ||||||||||||||||||||||
standardAppearance = customAppearance | ||||||||||||||||||||||
setupAppearance() | ||||||||||||||||||||||
Comment on lines
+567
to
+570
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm adding a suggestion - separating the appearance from behaviour. This is so that existing implementations in UIKit can modify the appearance in their own way (for example: one can modify the appearance by subclassing, accessing the properties, assigning a new appearance proxy or even by modifying the UIKit hierarchy directly). We've got all kinds of mess in our projects, and I hope this should make it more compatible. Also it supports the "separation of responsibilities" principle, since setting the appearance will be its own function, decoupled from the "model"/traits of the input field.
Suggested change
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/// Traits | ||||||||||||||||||||||
setupTraits(traits: model.traits ?? .default) | ||||||||||||||||||||||
setupToolbarIfNeeded(traits: model.traits ?? .default) | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the modifier to be named
.inputFieldAppearance
, as "Style
" reminds me of native SwiftUI modifiers, but those work in a different way, with their own Styles and Configurations. Setting the look of the input field globally is also nameddefaultAppearance
/globalAppearance
.