├── .gitattributes ├── .gitignore ├── LICENSE ├── Package.swift ├── README.md └── Sources └── Onboarding ├── OnboardingBulletinView.swift ├── OnboardingButton.swift ├── OnboardingButtonType.swift ├── OnboardingImageView.swift ├── OnboardingViewController.swift └── ThemeManager.swift /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 98 | __pypackages__/ 99 | 100 | # Celery stuff 101 | celerybeat-schedule 102 | celerybeat.pid 103 | 104 | # SageMath parsed files 105 | *.sage.py 106 | 107 | # Environments 108 | .env 109 | .venv 110 | env/ 111 | venv/ 112 | ENV/ 113 | env.bak/ 114 | venv.bak/ 115 | 116 | # Spyder project settings 117 | .spyderproject 118 | .spyproject 119 | 120 | # Rope project settings 121 | .ropeproject 122 | 123 | # mkdocs documentation 124 | /site 125 | 126 | # mypy 127 | .mypy_cache/ 128 | .dmypy.json 129 | dmypy.json 130 | 131 | # Pyre type checker 132 | .pyre/ 133 | 134 | # pytype static type analyzer 135 | .pytype/ 136 | 137 | # Cython debug symbols 138 | cython_debug/ 139 | 140 | .DS_Store 141 | /.build 142 | /Packages 143 | /*.xcodeproj 144 | xcuserdata/ 145 | 146 | # OS X 147 | .DS_Store 148 | 149 | # Xcode 150 | build/ 151 | *.pbxuser 152 | !default.pbxuser 153 | *.mode1v3 154 | !default.mode1v3 155 | *.mode2v3 156 | !default.mode2v3 157 | *.perspectivev3 158 | !default.perspectivev3 159 | xcuserdata 160 | *.xccheckout 161 | *.moved-aside 162 | DerivedData 163 | *.hmap 164 | *.ipa 165 | *.xcuserstate 166 | .swiftpm/ 167 | 168 | # Carthage 169 | /Carthage/ 170 | 171 | # Swift Package Manager 172 | .build 173 | Packages/ 174 | Pods/ 175 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.6 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "Onboarding", 8 | platforms: [ 9 | .iOS(.v11) 10 | ], 11 | products: [ 12 | // Products define the executables and libraries a package produces, and make them visible to other packages. 13 | .library( 14 | name: "Onboarding", 15 | targets: ["Onboarding"]), 16 | ], 17 | dependencies: [ 18 | // Dependencies declare other packages that this package depends on. 19 | // .package(url: /* package url */, from: "1.0.0"), 20 | ], 21 | targets: [ 22 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 23 | // Targets can depend on other targets in this package, and on products in packages this package depends on. 24 | .target( 25 | name: "Onboarding", 26 | dependencies: []) 27 | ] 28 | ) 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Onboarding 2 | Open Source Apple Like Onboarding Package 3 | -------------------------------------------------------------------------------- /Sources/Onboarding/OnboardingBulletinView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // OnboardingBulletinView.swift 3 | // 4 | // 5 | // Created by Somica on 29/09/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | /// A view which is added to the bulletin list in an `OnboardingViewController` 11 | public class OnboardingBulletinView: UIView { 12 | 13 | private var imageView: OnboardingImageView 14 | 15 | /// Initialize a bulletin using an SF Symbol 16 | /// - Parameters: 17 | /// - title: Title of bulletin 18 | /// - description: Description of bulletin 19 | /// - symbol: SF Symbol of bulletin 20 | @available(iOS 13, *) 21 | public init(title: String, description: String, symbol: String) { 22 | self.imageView = OnboardingImageView(symbolName: symbol, type: .bulletItem) 23 | 24 | super.init(frame: .zero) 25 | self.commonInit(title: title, description: description) 26 | } 27 | 28 | /// Initialize a bulletin using a `UIImage` 29 | /// - Parameters: 30 | /// - title: Title of bulletin 31 | /// - description: Description of bulletin 32 | /// - image: `UIImage` of bulletin. Note, this will be scaled to 43x40 33 | public init(title: String, description: String, image: UIImage) { 34 | self.imageView = OnboardingImageView(image: image, type: .bulletItem) 35 | 36 | super.init(frame: .zero) 37 | self.commonInit(title: title, description: description) 38 | } 39 | 40 | private func commonInit(title: String, description: String) { 41 | let stackView = UIStackView(frame: .zero) 42 | stackView.translatesAutoresizingMaskIntoConstraints = false 43 | stackView.distribution = .fill 44 | stackView.alignment = .center 45 | stackView.axis = .horizontal 46 | stackView.spacing = 15 47 | 48 | let titleLabel = UILabel(frame: .zero) 49 | titleLabel.translatesAutoresizingMaskIntoConstraints = false 50 | titleLabel.numberOfLines = 0 51 | titleLabel.text = title 52 | titleLabel.font = UIFont.systemFont(ofSize: 15, weight: .semibold) 53 | titleLabel.textColor = .labelColor 54 | 55 | let descriptionLabel = UILabel(frame: .zero) 56 | descriptionLabel.translatesAutoresizingMaskIntoConstraints = false 57 | descriptionLabel.numberOfLines = 0 58 | descriptionLabel.text = description 59 | descriptionLabel.font = UIFont.systemFont(ofSize: 15, weight: .regular) 60 | descriptionLabel.textColor = .secondaryLabelColor 61 | 62 | let textStackView = UIStackView(frame: .zero) 63 | textStackView.translatesAutoresizingMaskIntoConstraints = false 64 | textStackView.axis = .vertical 65 | textStackView.distribution = .fillProportionally 66 | textStackView.spacing = 0 67 | 68 | textStackView.addArrangedSubview(titleLabel) 69 | textStackView.addArrangedSubview(descriptionLabel) 70 | 71 | stackView.addArrangedSubview(imageView) 72 | stackView.addArrangedSubview(textStackView) 73 | 74 | addSubview(stackView) 75 | translatesAutoresizingMaskIntoConstraints = false 76 | NSLayoutConstraint.activate([ 77 | leadingAnchor.constraint(equalTo: stackView.leadingAnchor), 78 | trailingAnchor.constraint(equalTo: stackView.trailingAnchor), 79 | topAnchor.constraint(equalTo: stackView.topAnchor), 80 | bottomAnchor.constraint(equalTo: stackView.bottomAnchor), 81 | ]) 82 | } 83 | 84 | required public init?(coder: NSCoder) { 85 | fatalError("Init with coder is not supported :woeisme:") 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /Sources/Onboarding/OnboardingButton.swift: -------------------------------------------------------------------------------- 1 | // 2 | // OnboardingButton.swift 3 | // 4 | // 5 | // Created by Amy While on 17/11/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | /// A button that is added to the bottom of an `OnboardingViewController` 11 | public class OnboardingButton: UIButton { 12 | 13 | private let type: OnboardingButtonType 14 | private let title: String 15 | 16 | /// Initialize a button 17 | /// - Parameters: 18 | /// - type: The type of button to create, refer to `OnboardingButtonType` 19 | /// - title: The title for the button 20 | public init(type: OnboardingButtonType, title: String) { 21 | self.type = type 22 | self.title = title 23 | super.init(frame: .zero) 24 | _init() 25 | } 26 | 27 | private func _init() { 28 | translatesAutoresizingMaskIntoConstraints = false 29 | layer.masksToBounds = true 30 | layer.cornerRadius = 7.5 31 | switch type { 32 | case .clear(textColor: let textColor): 33 | setTitleColor(textColor, for: .normal) 34 | case .filled(color: let color): 35 | setTitleColor(.white, for: .normal) 36 | backgroundColor = color 37 | } 38 | 39 | setTitle(title, for: .normal) 40 | titleLabel?.font = .systemFont(ofSize: 15.5, weight: .regular) 41 | 42 | let height: Double 43 | switch Int(UIScreen.main.scale) { 44 | case 1, 2: height = 40 45 | default: height = 45 46 | } 47 | heightAnchor.constraint(equalToConstant: height).isActive = true 48 | } 49 | 50 | required init?(coder: NSCoder) { 51 | fatalError("init(coder:) has not been implemented") 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /Sources/Onboarding/OnboardingButtonType.swift: -------------------------------------------------------------------------------- 1 | // 2 | // OnboardingButtonType.swift 3 | // 4 | // 5 | // Created by Amy While on 17/11/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | /// Available types for `OnboardingButton` 11 | public enum OnboardingButtonType { 12 | /// A button that is filled with a solid color. Text color will always be white. 13 | /// - Parameters: 14 | /// - color: Fill color of the button. Typically this should be the tint color of the view 15 | case filled(color: UIColor) 16 | /// A button that is transparent. This should typically be used as the cancel option 17 | /// - Parameters: 18 | /// - textColor: Text color of the title. Typically this should be the tint color of the view 19 | case clear(textColor: UIColor) 20 | } 21 | -------------------------------------------------------------------------------- /Sources/Onboarding/OnboardingImageView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // OnboardingImageView.swift 3 | // 4 | // 5 | // Created by Somica on 28/09/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | internal enum ImageType { 11 | case header 12 | case bulletItem 13 | } 14 | 15 | internal class OnboardingImageView: UIImageView { 16 | 17 | internal convenience init(symbolName: String, type: ImageType) { 18 | if #available(iOS 13, *) { 19 | var symbolConfig: UIImage.SymbolConfiguration? 20 | if type == .header { 21 | symbolConfig = UIImage.SymbolConfiguration(pointSize: 46, weight: .regular) 22 | } 23 | let image = UIImage(systemName: symbolName, withConfiguration: symbolConfig) 24 | self.init(image: image, type: type) 25 | } else { 26 | self.init(image: nil, type: type) 27 | } 28 | } 29 | 30 | internal init(image: UIImage?, type: ImageType) { 31 | super.init(frame: .zero) 32 | self.image = image 33 | 34 | translatesAutoresizingMaskIntoConstraints = false 35 | 36 | switch type { 37 | case .header: 38 | NSLayoutConstraint.activate([ 39 | heightAnchor.constraint(equalToConstant: 90), 40 | widthAnchor.constraint(equalToConstant: 90) 41 | ]) 42 | contentMode = .scaleAspectFill 43 | layer.masksToBounds = true 44 | layer.cornerRadius = 11.25 45 | case .bulletItem: 46 | NSLayoutConstraint.activate([ 47 | widthAnchor.constraint(equalToConstant: 40), 48 | heightAnchor.constraint(equalToConstant: 43) 49 | ]) 50 | contentMode = .scaleAspectFit 51 | layer.masksToBounds = true 52 | layer.cornerRadius = 5.5 53 | } 54 | } 55 | 56 | required init?(coder: NSCoder) { 57 | fatalError("init(coder:) has not been implemented") 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Sources/Onboarding/OnboardingViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // OnboardingViewController.swift 3 | // 4 | // 5 | // Created by Somica on 28/09/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | /// View Controller shown for onboarding users 11 | public class OnboardingViewController: UIViewController { 12 | 13 | internal lazy var scrollView: UIScrollView = { 14 | let view = UIScrollView(frame: .zero) 15 | view.translatesAutoresizingMaskIntoConstraints = false 16 | view.isDirectionalLockEnabled = true 17 | view.delegate = self 18 | return view 19 | }() 20 | 21 | internal var bulletList: UIStackView = { 22 | let stackView = UIStackView() 23 | stackView.axis = .vertical 24 | stackView.distribution = .fillProportionally 25 | stackView.translatesAutoresizingMaskIntoConstraints = false 26 | stackView.spacing = 27.5 27 | return stackView 28 | }() 29 | 30 | internal var headerView: UIStackView = { 31 | let stackView = UIStackView() 32 | stackView.axis = .vertical 33 | stackView.distribution = .equalSpacing 34 | stackView.alignment = .center 35 | stackView.translatesAutoresizingMaskIntoConstraints = false 36 | stackView.spacing = 13.5 37 | return stackView 38 | }() 39 | 40 | internal var buttonTray: UIStackView = { 41 | let stackView = UIStackView() 42 | stackView.axis = .vertical 43 | stackView.distribution = .fill 44 | stackView.translatesAutoresizingMaskIntoConstraints = false 45 | stackView.spacing = 6.5 46 | return stackView 47 | }() 48 | 49 | internal var imageView: UIImageView? 50 | internal var descriptionLabel: UILabel? 51 | 52 | private var image: UIImage? 53 | private var symbolName: String? 54 | private var descriptionText: String? 55 | private var headerTitle: String? 56 | 57 | /// Initialize an onboarding view controller using an SF Symbol 58 | /// - Parameters: 59 | /// - title: Title of the view controller 60 | /// - description: Description of the view controller 61 | /// - symbolName: Name of the symbol 62 | /// - Note: 63 | /// Any omitted fields will not show in the view controller 64 | public init(title: String? = nil, description: String? = nil, symbolName: String? = nil) { 65 | self.symbolName = symbolName 66 | self.headerTitle = title 67 | self.descriptionText = description 68 | super.init(nibName: nil, bundle: nil) 69 | } 70 | 71 | /// Initialize an onboarding view controller using a `UIImage` 72 | /// - Parameters: 73 | /// - title: Title of the view controller 74 | /// - description: Description of the view controller 75 | /// - image: `UIImage` of view controller. Note: Will be scaled to 90x90 76 | /// - Note: 77 | /// Any omitted fields will not show in the view controller 78 | public init(title: String? = nil, description: String? = nil, image: UIImage? = nil) { 79 | self.image = image 80 | self.descriptionText = description 81 | self.headerTitle = title 82 | super.init(nibName: nil, bundle: nil) 83 | } 84 | 85 | public required init?(coder: NSCoder) { 86 | fatalError("init(coder:) has not been implemented") 87 | } 88 | 89 | private lazy var relativeTopAnchor = view.safeAreaLayoutGuide.topAnchor 90 | private lazy var relativeBottomAnchor = view.safeAreaLayoutGuide.bottomAnchor 91 | 92 | private func scaled(_ num: Double) -> Double { 93 | let scale = UIScreen.main.nativeScale 94 | return scale * num 95 | } 96 | 97 | public override func viewDidLoad() { 98 | super.viewDidLoad() 99 | 100 | view.addSubview(scrollView) 101 | view.addSubview(headerView) 102 | view.addSubview(buttonTray) 103 | view.backgroundColor = .backgroundColor 104 | 105 | scrollView.addSubview(bulletList) 106 | var constraints = [NSLayoutConstraint]() 107 | 108 | var headerImageView: OnboardingImageView? 109 | if let image = self.image { 110 | headerImageView = .init(image: image, type: .header) 111 | } else if let symbolName = self.symbolName { 112 | if #available(iOS 13, *) { 113 | headerImageView = .init(symbolName: symbolName, type: .header) 114 | } 115 | } 116 | if let headerImageView = headerImageView { 117 | headerView.addArrangedSubview(headerImageView) 118 | } 119 | 120 | if let title = self.headerTitle { 121 | let label = UILabel(frame: .zero) 122 | label.text = title 123 | label.numberOfLines = 1 124 | label.textAlignment = .center 125 | label.textColor = .labelColor 126 | label.translatesAutoresizingMaskIntoConstraints = false 127 | label.font = UIFont.systemFont(ofSize: 34, weight: .bold) 128 | label.adjustsFontSizeToFitWidth = true 129 | headerView.addArrangedSubview(label) 130 | constraints.append(label.heightAnchor.constraint(equalToConstant: 40)) 131 | } 132 | 133 | if let description = self.descriptionText { 134 | let label = UILabel(frame: .zero) 135 | label.translatesAutoresizingMaskIntoConstraints = false 136 | label.font = UIFont.systemFont(ofSize: 17) 137 | label.text = description 138 | label.numberOfLines = 0 139 | label.textColor = .labelColor 140 | label.textAlignment = .center 141 | headerView.addArrangedSubview(label) 142 | } 143 | 144 | relativeTopAnchor = headerView.bottomAnchor 145 | constraints += [ 146 | view.safeAreaLayoutGuide.topAnchor.constraint(equalTo: headerView.topAnchor, constant: scaled(-25.8)), 147 | view.safeAreaLayoutGuide.leadingAnchor.constraint(equalTo: headerView.leadingAnchor, constant: -12.5), 148 | view.safeAreaLayoutGuide.trailingAnchor.constraint(equalTo: headerView.trailingAnchor, constant: 12.5), 149 | 150 | scrollView.topAnchor.constraint(equalTo: relativeTopAnchor, constant: scaled(19.2)), 151 | scrollView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: scaled(18.3)), 152 | scrollView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: scaled(-18.3)), 153 | 154 | buttonTray.topAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: 15), 155 | buttonTray.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: scaled(14.3)), 156 | buttonTray.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: scaled(-14.3)), 157 | buttonTray.bottomAnchor.constraint(equalTo: relativeBottomAnchor, constant: scaled(-11)), 158 | 159 | bulletList.leadingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.leadingAnchor), 160 | bulletList.trailingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.trailingAnchor), 161 | bulletList.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor), 162 | bulletList.bottomAnchor.constraint(equalTo: scrollView.contentLayoutGuide.bottomAnchor), 163 | 164 | scrollView.frameLayoutGuide.widthAnchor.constraint(equalTo: bulletList.widthAnchor) 165 | ] 166 | relativeBottomAnchor = scrollView.bottomAnchor 167 | NSLayoutConstraint.activate(constraints) 168 | } 169 | 170 | /// Add a bulletin to the list 171 | /// - Parameter bulletin: Bulletin to be added 172 | public func addBulletin(_ bulletin: OnboardingBulletinView) { 173 | bulletList.addArrangedSubview(bulletin) 174 | } 175 | 176 | /// Add a button to the tray 177 | /// - Parameter button: Button to be added 178 | public func addButton(_ button: OnboardingButton) { 179 | buttonTray.addArrangedSubview(button) 180 | } 181 | 182 | /// Add a loading indicator to the bulletin list 183 | public func addLoadingIndicator() { 184 | let loadingIndicator: UIActivityIndicatorView 185 | if #available(iOS 13, *) { 186 | loadingIndicator = UIActivityIndicatorView(style: .large) 187 | } else { 188 | loadingIndicator = UIActivityIndicatorView(style: .whiteLarge) 189 | } 190 | loadingIndicator.startAnimating() 191 | bulletList.addArrangedSubview(loadingIndicator) 192 | } 193 | 194 | } 195 | 196 | extension OnboardingViewController: UIScrollViewDelegate { 197 | 198 | public func scrollViewDidScroll(_ scrollView: UIScrollView) { 199 | if(scrollView.contentOffset.x != 0){ 200 | scrollView.setContentOffset(CGPointMake(0, scrollView.contentOffset.y), animated: false) 201 | } 202 | } 203 | 204 | } 205 | -------------------------------------------------------------------------------- /Sources/Onboarding/ThemeManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ThemeManager.swift 3 | // Shimmer 4 | // 5 | // Created by Amy While on 20/07/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | internal final class ThemeManager { 11 | 12 | static let secondaryBackgroundColour: UIColor = { 13 | if #available(iOS 13, *) { 14 | return UIColor(dynamicProvider: { traitCollection in 15 | if traitCollection.userInterfaceStyle == .dark { 16 | return .systemGray6 17 | } else { 18 | return .white 19 | } 20 | }) 21 | } 22 | return .white 23 | }() 24 | 25 | static let backgroundColour: UIColor = { 26 | if #available(iOS 13, *) { 27 | return .systemBackground 28 | } 29 | return .white 30 | }() 31 | 32 | static let secondaryLabel: UIColor = { 33 | UIColor(red: 0.56, green: 0.56, blue: 0.58, alpha: 1) 34 | }() 35 | 36 | static let label: UIColor = { 37 | if #available(iOS 13, *) { 38 | return .label 39 | } 40 | return .black 41 | }() 42 | } 43 | 44 | internal extension UIColor { 45 | 46 | static var backgroundColor: UIColor { 47 | ThemeManager.backgroundColour 48 | } 49 | 50 | static var secondaryBackgroundColor: UIColor { 51 | ThemeManager.secondaryBackgroundColour 52 | } 53 | 54 | static var secondaryLabelColor: UIColor { 55 | ThemeManager.secondaryLabel 56 | } 57 | 58 | static var labelColor: UIColor { 59 | ThemeManager.label 60 | } 61 | 62 | } 63 | --------------------------------------------------------------------------------