[ISSUE] Add logger to colorable on fallBack (#62)
[ISSUE] added logger to colorable on failBack
[CM-1324] Update documentation comments
Co-authored-by: Mark Pospesel mark.pospesel@ymedialabs.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802032778号
Core components for iOS to accelerate building user interfaces in code.
This lightweight framework primarily comprises:
It also contains miscellaneous other Foundation and UIKit extensions.
Licensing
Y—CoreUI is licensed under the Apache 2.0 license.
Documentation
Documentation is automatically generated from source code comments and rendered as a static website hosted via GitHub Pages at: https://yml-org.github.io/YCoreUI/
Usage
1. UIView extensions for declarative Auto Layout
To aid in auto layout, Y—CoreUI has several
UIViewextensions that simplify creating layout constraints. These do not use any 3rd party library such as SnapKit, but are simply wrappers around Apple’s ownNSLayoutConstraintapi’s. If you are more comfortable using Apple’s layout constraint api’s natively, then by all means go ahead and use them. But these convenience methods allow for less verbose code that expresses its intent more directly.All the extensions are to
UIViewand begin with the wordconstrain.The simplest flavor just creates constraints using attributes just like the original iOS 6
NSLayoutContraintapi.Another flavor creates constraints using anchors just like the anchor api’s first introduced in iOS 9.
There are overrides to handle the common use case of placing one view below another or to the trailing side of another:
But where these extensions really shine are the
constrainEdgesmethods that create up to four constraints with a single method call.There’s also a
constrainEdgesToMarginsvariant that sets constraints between the recipient’s edges and the layout margins of the specified view (typically the recipient’s superview). This is very handy for avoiding safe areas such as the region occupied by the navigation bar or by the FaceID notch.Constrain size
There are three convenience methods for constraining the size of a view.
Constrain center
There is an Auto Layout convenience method for centering views.
Constrain aspect ratio
There is an Auto Layout convenience method for constraining aspect ratio:
2. Protocols to aid loading string, color, and image assets
We have extensions that accelerate loading strings, colors, and images (and make it easy to unit test them).
LocalizableEasily load localized string resources from any string-based
Enum. All you need to do is declare conformance toLocalizableand you gain access to alocalized: Stringproperty.Unit testing is then easy:
The protocol also allows you to specify the bundle containing the localized strings and the optional table name.
ColorableEasily load color assets from any string-based
Enum. All you need to do is declare conformance toColorableand you gain access to acolor: Colorproperty. You can even define afallbackColorinstead ofnilor.clearso that UI elements won’t be invisible in the event of a failure (but they’re bright pink by default to catch your eye).Unit testing is easy:
The protocol also allows you to specify the bundle containing the color assets, the optional namespace, and the fallback color.
ImageAssetEasily load image assets from any string-based
Enum. All you need to do is declare conformance toImageAssetand you gain access to animage: UIImageproperty. You can even define afallbackImageinstead ofnilso that UI elements won’t be invisible in the event of a failure (but it’s a bright pink square by default to catch your eye).If you add
CaseIterableto your enum, then it becomes super simple to write unit tests to make sure they’re working properly (and you can add, update, modify the enum cases without needing to update your unit test).The protocol also allows you to specify the bundle containing the image assets, the optional namespace, and the fallback image.
SystemImageEasily load system images (SF Symbols) from any string-based
Enum. All you need to do is declare conformance toSystemImageand you gain access to animage: UIImageproperty. LikeImageAssetabove, you can define afallbackImage.Why bother doing this when it just wraps
UIImage(systemName:)? BecauseUIImage(systemName:)returnsUIImage?whileSystemImage.imagereturnsUIImage.SystemImage.imagereturns images that scale with Dynamic Type.If you add
CaseIterableto your enum, then it becomes super simple to write unit tests to make sure they’re working properly (and you can add, update, modify the enum cases without needing to update your unit test).3. UIColor extensions for WCAG 2.0 contrast ratio calculations
Y—CoreUI contains a number of extensions to make working with colors easier. The most useful of them may be WCAG 2.0 contrast calculations. Given any two colors (representing foreground and background colors), you can calculate the contrast ration between them and evaluate whether that passes particular WCAG 2.0 standards (AA or AAA). You can even write unit tests to quickly check all color pairs in your app across all color modes. That could look like this:
4. UIScrollView extensions to assist with keyboard avoidance
FormViewController
FormViewControlleris a view controller with a scrollable content area that will automatically avoid the keyboard for you. It is a good choice for views that have inputs (e.g. login or onboarding). Even for views without inputs, it is still quite useful for managing the creation of aUIScrollViewand acontentViewset within it, so that you can focus on your content and not have to code a scrollView for every view.UIScrollview Extensions
Want to have a scrollview that avoids the keyboard, but you can’t use
FormViewController? Most of its functionality is a simple extension toUIScrollView. You can add keyboard avoidance to any scroll view like so:5. Other
Elevation
Elevationis a model object to define shadows similarly to W3C box-shadows and Figma drop shadows. It has the following parameters that match how Figma (and web) define drop shadows:Elevationhas anapplymethod that then applies that shadow effect to aCALayer. Remember to call it every time your color mode changes to update the shadow color (aCGColor).Animation
Animationis a model object to define UIView animations. It has the following parameters:Animation.curveis an enum with associated values that can be either.regularor.spring.There is a
UIViewclass override method foranimatethat takes anAnimationobject.The advantage of adopting the
Animationstructure is that with a single method you can animate either a regular or spring animation. This allows us to build components where the user can customize the animations used without having our code be overly complex or fragile.Installation
You can add Y-CoreUI to an Xcode project by adding it as a package dependency.
Contributing to Y-CoreUI
Requirements
SwiftLint (linter)
Jazzy (documentation)
Setup
Clone the repo and open
Package.swiftin Xcode.Versioning strategy
We utilize semantic versioning.
e.g.
Branching strategy
We utilize a simplified branching strategy for our frameworks.
mainmainmainas they are completed and approved.maingets tagged with an updated version # for each releaseBranch naming conventions:
e.g.
Pull Requests
Prior to submitting a pull request you should:
swiftlintfrom the command line and confirm that there are no violations.jazzyfrom the command line and confirm that you have 100% documentation coverage.git rebase -i HEAD~{commit-count}to squash your last {commit-count} commits together into functional chunks.main) has been updated since you created your branch, usegit rebase mainto rebase your branch.When submitting a pull request:
When merging a pull request:
Releasing new versions
1.0.5)Generating Documentation (via Jazzy)
You can generate your own local set of documentation directly from the source code using the following command from Terminal:
This generates a set of documentation under
/docs. The default configuration is set in the default config file.jazzy.yamlfile.To view additional documentation options type:
A GitHub Action automatically runs each time a commit is pushed to
mainthat runs Jazzy to generate the documentation for our GitHub page at: https://yml-org.github.io/YCoreUI/