├── Assets ├── github.png ├── movie.gif ├── Logo.sketch └── preview.jpg ├── Example ├── Example │ ├── Assets.xcassets │ │ ├── Contents.json │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── AppDelegate.swift │ ├── Base.lproj │ │ ├── Main.storyboard │ │ └── LaunchScreen.storyboard │ ├── Info.plist │ ├── ViewController.swift │ └── SceneDelegate.swift └── Example.xcodeproj │ ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── swiftpm │ │ └── Package.resolved │ ├── xcshareddata │ └── xcschemes │ │ └── Example.xcscheme │ └── project.pbxproj ├── Tests ├── LinuxMain.swift └── BaulettoTests │ ├── XCTestManifests.swift │ └── BannerTests.swift ├── .swiftpm └── xcode │ └── package.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── .github └── FUNDING.yml ├── Sources └── Bauletto │ ├── BaulettoDismissMode.swift │ ├── FeedbackGenerator.swift │ ├── BaulettoSettings.swift │ └── Bauletto.swift ├── Package.swift ├── Configs └── Info.plist ├── LICENSE ├── .gitignore └── README.md /Assets/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gianpispi/Bauletto/HEAD/Assets/github.png -------------------------------------------------------------------------------- /Assets/movie.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gianpispi/Bauletto/HEAD/Assets/movie.gif -------------------------------------------------------------------------------- /Assets/Logo.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gianpispi/Bauletto/HEAD/Assets/Logo.sketch -------------------------------------------------------------------------------- /Assets/preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gianpispi/Bauletto/HEAD/Assets/preview.jpg -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import BannerTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += BannerTests.allTests() 7 | XCTMain(tests) 8 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Tests/BaulettoTests/XCTestManifests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | #if !canImport(ObjectiveC) 4 | public func allTests() -> [XCTestCaseEntry] { 5 | return [ 6 | testCase(BannerTests.allTests), 7 | ] 8 | } 9 | #endif 10 | -------------------------------------------------------------------------------- /Tests/BaulettoTests/BannerTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import Bauletto 3 | 4 | final class BannerTests: XCTestCase { 5 | func testExample() { 6 | 7 | } 8 | 9 | static var allTests = [ 10 | ("testExample", testExample), 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "Bauletto", 6 | "repositoryURL": "/Users/gianpierospinelli/Documents/SVILUPPO/Bauletto", 7 | "state": { 8 | "branch": "master", 9 | "revision": "5b8cbe9cefbfdbe43362fe9cb8d10d6f9bddd088", 10 | "version": null 11 | } 12 | } 13 | ] 14 | }, 15 | "version": 1 16 | } 17 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: https://www.paypal.me/gianpispi 13 | -------------------------------------------------------------------------------- /Sources/Bauletto/BaulettoDismissMode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BaulettoDismissMode.swift 3 | // 4 | // 5 | // Created by Gianpiero Spinelli on 06/03/2020. 6 | // 7 | 8 | import Foundation 9 | 10 | public enum BaulettoDismissMode: Equatable { 11 | /// Hide the banner view after the default duration. 12 | case automatic 13 | 14 | /// Disables automatic hiding of the message view. 15 | case never 16 | 17 | /// Custom duration. 18 | case custom(seconds: TimeInterval) 19 | 20 | public var duration: TimeInterval { 21 | switch self { 22 | case .automatic: return 4 23 | case .never: return 0 24 | case .custom(let seconds): return seconds 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 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: "Bauletto", 8 | platforms: [.iOS(.v10)], 9 | products: [ 10 | .library( 11 | name: "Bauletto", 12 | targets: ["Bauletto"]), 13 | ], 14 | dependencies: [ 15 | // Dependencies declare other packages that this package depends on. 16 | // .package(url: /* package url */, from: "1.0.0"), 17 | ], 18 | targets: [ 19 | .target( 20 | name: "Bauletto", 21 | dependencies: []), 22 | .testTarget( 23 | name: "BaulettoTests", 24 | dependencies: ["Bauletto"]), 25 | ] 26 | ) 27 | -------------------------------------------------------------------------------- /Configs/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Gianpiero Spinelli 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Example/Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Example 4 | // 5 | // Created by Gianpiero Spinelli on 16/10/2020. 6 | // Copyright © 2020 Gianpiero Spinelli. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | // MARK: UISceneSession Lifecycle 22 | 23 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 24 | // Called when a new scene session is being created. 25 | // Use this method to select a configuration to create the new scene with. 26 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 27 | } 28 | 29 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 30 | // Called when the user discards a scene session. 31 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 32 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 33 | } 34 | 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Example/Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Example/Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Sources/Bauletto/FeedbackGenerator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FeedbackGenerator.swift 3 | // 4 | // 5 | // Created by Gianpiero Spinelli on 06/03/2020. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | public class FeedbackGenerator: NSObject { 12 | public enum HapticStyle { 13 | case notificationError, notificationWarning, notificationSuccess 14 | case light, medium, heavy 15 | case none 16 | 17 | @available(iOS 13, *) 18 | case soft, rigid 19 | 20 | fileprivate var impactGenerator: UIImpactFeedbackGenerator.FeedbackStyle? { 21 | switch self { 22 | case .light: return .light 23 | case .medium: return .medium 24 | case .heavy: return .heavy 25 | case .soft: 26 | if #available(iOS 13, *) { 27 | return .soft 28 | } else { 29 | return nil 30 | } 31 | case .rigid: 32 | if #available(iOS 13, *) { 33 | return .rigid 34 | } else { 35 | return nil 36 | } 37 | default: return nil 38 | } 39 | } 40 | } 41 | 42 | public class func generate(withStyle style: HapticStyle) { 43 | switch style { 44 | case .notificationError: 45 | let generator = UINotificationFeedbackGenerator() 46 | generator.notificationOccurred(.error) 47 | 48 | case .notificationSuccess: 49 | let generator = UINotificationFeedbackGenerator() 50 | generator.notificationOccurred(.success) 51 | 52 | case .notificationWarning: 53 | let generator = UINotificationFeedbackGenerator() 54 | generator.notificationOccurred(.warning) 55 | 56 | case .light, .medium, .heavy, .soft, .rigid: 57 | if let style = style.impactGenerator { 58 | let generator = UIImpactFeedbackGenerator(style: style) 59 | generator.impactOccurred() 60 | } 61 | 62 | case .none: break 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Example/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIMainStoryboardFile 45 | Main 46 | UIRequiredDeviceCapabilities 47 | 48 | armv7 49 | 50 | UISupportedInterfaceOrientations 51 | 52 | UIInterfaceOrientationPortrait 53 | UIInterfaceOrientationLandscapeLeft 54 | UIInterfaceOrientationLandscapeRight 55 | 56 | UISupportedInterfaceOrientations~ipad 57 | 58 | UIInterfaceOrientationPortrait 59 | UIInterfaceOrientationPortraitUpsideDown 60 | UIInterfaceOrientationLandscapeLeft 61 | UIInterfaceOrientationLandscapeRight 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /Example/Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Example 4 | // 5 | // Created by Gianpiero Spinelli on 06/03/2020. 6 | // Copyright © 2020 Gianpiero Spinelli. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Bauletto 11 | 12 | class ViewController: UIViewController { 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | let button = UIButton() 17 | button.setTitle("Show Bauletto", for: .normal) 18 | button.setTitleColor(.systemBlue, for: .normal) 19 | button.addTarget(self, action: #selector(showWifiError), for: .touchUpInside) 20 | 21 | view.addSubview(button) 22 | button.translatesAutoresizingMaskIntoConstraints = false 23 | 24 | NSLayoutConstraint.activate([ 25 | button.centerXAnchor.constraint(equalTo: view.centerXAnchor), 26 | button.centerYAnchor.constraint(equalTo: view.centerYAnchor), 27 | ]) 28 | } 29 | 30 | override func viewDidAppear(_ animated: Bool) { 31 | super.viewDidAppear(animated) 32 | 33 | let settings = BaulettoSettings(icon: UIImage(systemName: "checkmark.seal.fill", withConfiguration: UIImage.SymbolConfiguration(weight: .semibold)), title: "It works", dismissMode: .automatic, hapticStyle: .notificationSuccess) 34 | Bauletto.show(withSettings: settings) 35 | 36 | let settings2 = BaulettoSettings(icon: UIImage(systemName: "hexagon", withConfiguration: UIImage.SymbolConfiguration(weight: .semibold)), title: "Blue tint color", tintColor: .blue, backgroundStyle: .dark, dismissMode: .custom(seconds: 2)) 37 | Bauletto.show(withSettings: settings2) 38 | } 39 | 40 | // Simulates a wifi error banner. 41 | @objc func showWifiError() { 42 | // dismiss mode set as never, so we have to call the hide manually. 43 | let settings3 = BaulettoSettings(icon: UIImage(systemName: "wifi.slash", withConfiguration: UIImage.SymbolConfiguration(weight: .semibold)), title: "Wifi lost", tintColor: .red, backgroundStyle: .systemChromeMaterial, dismissMode: .never) 44 | Bauletto.show(withSettings: settings3) 45 | 46 | // Hide the last banner after 10 seconds, since the dismissMode is `.never`. 47 | DispatchQueue.main.asyncAfter(deadline: .now() + 10) { 48 | Bauletto.hide() 49 | } 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /Example/Example/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // Example 4 | // 5 | // Created by Gianpiero Spinelli on 16/10/2020. 6 | // Copyright © 2020 Gianpiero Spinelli. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 12 | 13 | var window: UIWindow? 14 | 15 | 16 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 17 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 18 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 19 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 20 | guard let _ = (scene as? UIWindowScene) else { return } 21 | } 22 | 23 | func sceneDidDisconnect(_ scene: UIScene) { 24 | // Called as the scene is being released by the system. 25 | // This occurs shortly after the scene enters the background, or when its session is discarded. 26 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 27 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 28 | } 29 | 30 | func sceneDidBecomeActive(_ scene: UIScene) { 31 | // Called when the scene has moved from an inactive state to an active state. 32 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 33 | } 34 | 35 | func sceneWillResignActive(_ scene: UIScene) { 36 | // Called when the scene will move from an active state to an inactive state. 37 | // This may occur due to temporary interruptions (ex. an incoming phone call). 38 | } 39 | 40 | func sceneWillEnterForeground(_ scene: UIScene) { 41 | // Called as the scene transitions from the background to the foreground. 42 | // Use this method to undo the changes made on entering the background. 43 | } 44 | 45 | func sceneDidEnterBackground(_ scene: UIScene) { 46 | // Called as the scene transitions from the foreground to the background. 47 | // Use this method to save data, release shared resources, and store enough scene-specific state information 48 | // to restore the scene back to its current state. 49 | } 50 | 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Sources/Bauletto/BaulettoSettings.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BaulettoSettings.swift 3 | // 4 | // 5 | // Created by Gianpiero Spinelli on 06/03/2020. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | public struct BaulettoSettings { 12 | /// Icon that goes at the left of the text. 13 | public var icon: UIImage? 14 | 15 | /// Text that goes at the right of the image. 16 | public var title: String? 17 | 18 | /// Tint color for icon and title. 19 | public var tintColor: UIColor! 20 | 21 | /// Font for title. 22 | public var font: UIFont! = .boldSystemFont(ofSize: UIFont.labelFontSize) 23 | 24 | /// Style of the background UIVisualEffectView. 25 | public var backgroundStyle: UIBlurEffect.Style! = .regular 26 | 27 | /// Dismiss mode. Default is automatic 28 | public var dismissMode: BaulettoDismissMode = .automatic 29 | 30 | /// Type of the haptic feedback fired when the banner is shown. None by default. 31 | public var hapticStyle: FeedbackGenerator.HapticStyle = .none 32 | 33 | /// Duration of the fade in animation 34 | public var fadeInDuration: TimeInterval = 1 35 | 36 | /// The optional action that needs to be performed when the view is tapped. 37 | public var action: (() -> Void)? 38 | 39 | public init(icon: UIImage?, 40 | title: String?, 41 | backgroundStyle: UIBlurEffect.Style = .regular, 42 | dismissMode: BaulettoDismissMode = .automatic, 43 | hapticStyle: FeedbackGenerator.HapticStyle = .none, 44 | action: (() -> Void)? = nil, 45 | fadeInDuration: TimeInterval = 1) { 46 | self.icon = icon 47 | self.title = title 48 | self.backgroundStyle = backgroundStyle 49 | self.dismissMode = dismissMode 50 | self.hapticStyle = hapticStyle 51 | self.action = action 52 | self.fadeInDuration = fadeInDuration 53 | } 54 | 55 | public init(icon: UIImage?, 56 | title: String?, 57 | tintColor: UIColor, 58 | font: UIFont, 59 | backgroundStyle: UIBlurEffect.Style = .regular, 60 | dismissMode: BaulettoDismissMode = .automatic, 61 | hapticStyle: FeedbackGenerator.HapticStyle = .none, 62 | action: (() -> Void)? = nil, 63 | fadeInDuration: TimeInterval = 1) { 64 | self.icon = icon 65 | self.title = title 66 | self.tintColor = tintColor 67 | self.font = font 68 | self.backgroundStyle = backgroundStyle 69 | self.dismissMode = dismissMode 70 | self.hapticStyle = hapticStyle 71 | self.action = action 72 | self.fadeInDuration = fadeInDuration 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 45 | 51 | 52 | 53 | 54 | 60 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/osx,xcode,macos,swift,swiftpm,carthage,swiftpackagemanager 3 | # Edit at https://www.gitignore.io/?templates=osx,xcode,macos,swift,swiftpm,carthage,swiftpackagemanager 4 | 5 | ### Carthage ### 6 | # Carthage 7 | # 8 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 9 | # Carthage/Checkouts 10 | 11 | Carthage/Build 12 | 13 | ### macOS ### 14 | # General 15 | .DS_Store 16 | .AppleDouble 17 | .LSOverride 18 | 19 | # Icon must end with two \r 20 | Icon 21 | 22 | # Thumbnails 23 | ._* 24 | 25 | # Files that might appear in the root of a volume 26 | .DocumentRevisions-V100 27 | .fseventsd 28 | .Spotlight-V100 29 | .TemporaryItems 30 | .Trashes 31 | .VolumeIcon.icns 32 | .com.apple.timemachine.donotpresent 33 | 34 | # Directories potentially created on remote AFP share 35 | .AppleDB 36 | .AppleDesktop 37 | Network Trash Folder 38 | Temporary Items 39 | .apdisk 40 | 41 | ### OSX ### 42 | # General 43 | 44 | # Icon must end with two \r 45 | 46 | # Thumbnails 47 | 48 | # Files that might appear in the root of a volume 49 | 50 | # Directories potentially created on remote AFP share 51 | 52 | ### Swift ### 53 | # Xcode 54 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 55 | 56 | ## Build generated 57 | build/ 58 | DerivedData/ 59 | 60 | ## Various settings 61 | *.pbxuser 62 | !default.pbxuser 63 | *.mode1v3 64 | !default.mode1v3 65 | *.mode2v3 66 | !default.mode2v3 67 | *.perspectivev3 68 | !default.perspectivev3 69 | xcuserdata/ 70 | 71 | ## Other 72 | *.moved-aside 73 | *.xccheckout 74 | *.xcscmblueprint 75 | 76 | ## Obj-C/Swift specific 77 | *.hmap 78 | *.ipa 79 | *.dSYM.zip 80 | *.dSYM 81 | 82 | ## Playgrounds 83 | timeline.xctimeline 84 | playground.xcworkspace 85 | 86 | # Swift Package Manager 87 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 88 | # Packages/ 89 | # Package.pins 90 | # Package.resolved 91 | .build/ 92 | # Add this line if you want to avoid checking in Xcode SPM integration. 93 | # .swiftpm/xcode 94 | 95 | # CocoaPods 96 | # We recommend against adding the Pods directory to your .gitignore. However 97 | # you should judge for yourself, the pros and cons are mentioned at: 98 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 99 | # Pods/ 100 | # Add this line if you want to avoid checking in source code from the Xcode workspace 101 | # *.xcworkspace 102 | 103 | # Carthage 104 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 105 | # Carthage/Checkouts 106 | 107 | 108 | # Accio dependency management 109 | Dependencies/ 110 | .accio/ 111 | 112 | # fastlane 113 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 114 | # screenshots whenever they are needed. 115 | # For more information about the recommended setup visit: 116 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 117 | 118 | fastlane/report.xml 119 | fastlane/Preview.html 120 | fastlane/screenshots/**/*.png 121 | fastlane/test_output 122 | 123 | # Code Injection 124 | # After new code Injection tools there's a generated folder /iOSInjectionProject 125 | # https://github.com/johnno1962/injectionforxcode 126 | 127 | iOSInjectionProject/ 128 | 129 | ### SwiftPackageManager ### 130 | Packages 131 | xcuserdata 132 | 133 | 134 | ### SwiftPM ### 135 | 136 | 137 | ### Xcode ### 138 | # Xcode 139 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 140 | 141 | ## User settings 142 | 143 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 144 | 145 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 146 | 147 | ## Xcode Patch 148 | Bauletto.xcodeproj/* 149 | 150 | ### Xcode Patch ### 151 | **/xcshareddata/WorkspaceSettings.xcsettings 152 | 153 | # End of https://www.gitignore.io/api/osx,xcode,macos,swift,swiftpm,carthage,swiftpackagemanager -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Bauletto](Assets/github.png) 2 | 3 |

4 | 5 | Carthage 6 | 7 | Swift Package Manager 8 | 9 | iOS 10 | 11 | Twitter: @gianpispi 12 | 13 |

14 | 15 | #### Lightweight iOS 13 badge like with ease. 16 | 17 | ## Preview 18 |

19 | Bauletto 20 |

21 | 22 | ## Features 23 | - Highly customizable ✅ 24 | - iPhone, iPhone X, & iPad Support ✅ 25 | - Orientation change support ✅ 26 | - Haptic feeback support ✅ 27 | 28 | ## Requirements 29 | 30 | - iOS 10.0+ 31 | - Xcode 10.0+ 32 | 33 | ## Installation 34 | 35 | ### Carthage 36 | 37 | In order to use Bauletto via Carthage simply add this line to your `Cartfile`: 38 | 39 | #### Swift 5 40 | ```swift 41 | github "gianpispi/Bauletto" 42 | ``` 43 | Then add `Bauletto.framework` in your project. 44 | 45 | ### Swift Package Manager 46 | 47 | The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. 48 | 49 | Once you have your Swift package set up, adding Bauletto as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. 50 | 51 | ```swift 52 | dependencies: [ 53 | .package(url: "https://github.com/gianpispi/Bauletto.git", from: "1.0.6") 54 | ] 55 | ``` 56 | 57 | 58 | ## Usage 59 | 60 | Creating a Bauletto is simple as this: 61 | 62 | ```swift 63 | let settings = BaulettoSettings(icon: UIImage(systemName: "checkmark.seal.fill", withConfiguration: UIImage.SymbolConfiguration(weight: .semibold)), title: "It works") 64 | Bauletto.show(withSettings: settings) 65 | ``` 66 | 67 | If you want to change the tint color of the Bauletto, just use the `tintColor` value in the BaulettoSettings declaration as follows: 68 | 69 | ```swift 70 | let settings = BaulettoSettings(icon: UIImage(systemName: "checkmark.seal.fill", withConfiguration: UIImage.SymbolConfiguration(weight: .semibold)), title: "It works", tintColor: .red) 71 | Bauletto.show(withSettings: settings) 72 | ``` 73 | 74 | To change the background blur effect, add the `backgroundStyle`: 75 | 76 | ```swift 77 | let settings = BaulettoSettings(icon: UIImage(systemName: "checkmark.seal.fill", withConfiguration: UIImage.SymbolConfiguration(weight: .semibold)), title: "It works", backgroundStyle: .dark) 78 | Bauletto.show(withSettings: settings) 79 | ``` 80 | 81 | You can even change the dismissMode, which can be `.never`, `automatic` or `.custom(seconds: 2)`. By default it uses the automatic. 82 | 83 | ```swift 84 | let settings = BaulettoSettings(icon: UIImage(systemName: "checkmark.seal.fill", withConfiguration: UIImage.SymbolConfiguration(weight: .semibold)), title: "It works", dismissMode: .never) 85 | Bauletto.show(withSettings: settings) 86 | ``` 87 | 88 | You can also change the duration of the show animation. By default it uses 1.0 second. 89 | 90 | ```swift 91 | let settings = BaulettoSettings(icon: UIImage(systemName: "checkmark.seal.fill", withConfiguration: UIImage.SymbolConfiguration(weight: .semibold)), title: "It works", dismissMode: .never, fadeInDuration: 2.0) 92 | Bauletto.show(withSettings: settings) 93 | ``` 94 | 95 | Bauletto has a personal queue for the banners that will show up. When you show a banner you can select where in the queue it will be put. By default it is `.end`. 96 | 97 | ```swift 98 | public enum QueuePosition { 99 | case beginning, end 100 | } 101 | 102 | Bauletto.show(withSettings: settings, queuePosition: .beginning) 103 | ``` 104 | 105 | When you want to show up a new message immediately, add it by using the `show()` function, and then use: 106 | ```swift 107 | Bauletto.shared.forceShowNext() 108 | ``` 109 | 110 | Do you have a bunch of settings in the queue and you want to remove them? No problem. 111 | ```swift 112 | Bauletto.shared.removeBannersInQueue() 113 | ``` 114 | 115 | Bauletto can also have an action for a tap gesture. If you pass the `action` parameter, it will call the closure once the user tapped the banner. 116 | 117 | ```swift 118 | let settings = BaulettoSettings(icon: UIImage(systemName: "checkmark.seal.fill", withConfiguration: UIImage.SymbolConfiguration(weight: .semibold)), title: "It works", dismissMode: .never, action: { 119 | print("Hello, my name is Bauletto, and you tapped me!") 120 | }) 121 | Bauletto.show(withSettings: settings) 122 | ``` 123 | 124 | ## Haptic Feedback Support 125 | You can also set a haptic feedback when the Bauletto shows up. By default, no haptic feedback will be generated. The types of haptic feedback are as follows: 126 | 127 | ```swift 128 | public enum HapticStyle { 129 | case notificationError 130 | case notificationWarning 131 | case notificationSuccess 132 | 133 | case light 134 | case medium 135 | case heavy 136 | case none 137 | 138 | case soft 139 | case rigid 140 | } 141 | ``` 142 | 143 | To change the style of haptic feedback, simply declare it in the BaulettoSettings initialization: 144 | 145 | ```swift 146 | let settings = BaulettoSettings(icon: UIImage(systemName: "checkmark.seal.fill"), title: "It works", backgroundStyle: .systemChromeMaterial, dismissMode: .automatic, hapticStyle: .notificationSuccess) 147 | ``` 148 | 149 | ## Feature Requests 150 | I'd love to know improve Bauletto as much as I can. Feel free to open an issue and I'll do everything I can to accomodate that request if it is in the library's best interest. Or just create a pull request and I'll check it out. 151 | 152 | ## Author 153 | Gianpiero Spinelli, gianpiero@grspinelli.it 154 | 155 | ## License 156 | Bauletto is available under the MIT license. See the LICENSE file for more info. 157 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 52; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D657799C25398F950054F5C5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D657799B25398F950054F5C5 /* AppDelegate.swift */; }; 11 | D657799E25398F950054F5C5 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D657799D25398F950054F5C5 /* SceneDelegate.swift */; }; 12 | D65779A025398F950054F5C5 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D657799F25398F950054F5C5 /* ViewController.swift */; }; 13 | D65779A325398F950054F5C5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D65779A125398F950054F5C5 /* Main.storyboard */; }; 14 | D65779A525398F950054F5C5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D65779A425398F950054F5C5 /* Assets.xcassets */; }; 15 | D65779A825398F950054F5C5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D65779A625398F950054F5C5 /* LaunchScreen.storyboard */; }; 16 | D65779B125398FB60054F5C5 /* Bauletto in Frameworks */ = {isa = PBXBuildFile; productRef = D65779B025398FB60054F5C5 /* Bauletto */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | D657799825398F950054F5C5 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | D657799B25398F950054F5C5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | D657799D25398F950054F5C5 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 23 | D657799F25398F950054F5C5 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | D65779A225398F950054F5C5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | D65779A425398F950054F5C5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | D65779A725398F950054F5C5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | D65779A925398F950054F5C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | /* End PBXFileReference section */ 29 | 30 | /* Begin PBXFrameworksBuildPhase section */ 31 | D657799525398F950054F5C5 /* Frameworks */ = { 32 | isa = PBXFrameworksBuildPhase; 33 | buildActionMask = 2147483647; 34 | files = ( 35 | D65779B125398FB60054F5C5 /* Bauletto in Frameworks */, 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | D657798F25398F950054F5C5 = { 43 | isa = PBXGroup; 44 | children = ( 45 | D657799A25398F950054F5C5 /* Example */, 46 | D657799925398F950054F5C5 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | D657799925398F950054F5C5 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | D657799825398F950054F5C5 /* Example.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | D657799A25398F950054F5C5 /* Example */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | D657799B25398F950054F5C5 /* AppDelegate.swift */, 62 | D657799D25398F950054F5C5 /* SceneDelegate.swift */, 63 | D657799F25398F950054F5C5 /* ViewController.swift */, 64 | D65779A125398F950054F5C5 /* Main.storyboard */, 65 | D65779A425398F950054F5C5 /* Assets.xcassets */, 66 | D65779A625398F950054F5C5 /* LaunchScreen.storyboard */, 67 | D65779A925398F950054F5C5 /* Info.plist */, 68 | ); 69 | path = Example; 70 | sourceTree = ""; 71 | }; 72 | /* End PBXGroup section */ 73 | 74 | /* Begin PBXNativeTarget section */ 75 | D657799725398F950054F5C5 /* Example */ = { 76 | isa = PBXNativeTarget; 77 | buildConfigurationList = D65779AC25398F950054F5C5 /* Build configuration list for PBXNativeTarget "Example" */; 78 | buildPhases = ( 79 | D657799425398F950054F5C5 /* Sources */, 80 | D657799525398F950054F5C5 /* Frameworks */, 81 | D657799625398F950054F5C5 /* Resources */, 82 | ); 83 | buildRules = ( 84 | ); 85 | dependencies = ( 86 | ); 87 | name = Example; 88 | packageProductDependencies = ( 89 | D65779B025398FB60054F5C5 /* Bauletto */, 90 | ); 91 | productName = Example; 92 | productReference = D657799825398F950054F5C5 /* Example.app */; 93 | productType = "com.apple.product-type.application"; 94 | }; 95 | /* End PBXNativeTarget section */ 96 | 97 | /* Begin PBXProject section */ 98 | D657799025398F950054F5C5 /* Project object */ = { 99 | isa = PBXProject; 100 | attributes = { 101 | LastSwiftUpdateCheck = 1110; 102 | LastUpgradeCheck = 1110; 103 | ORGANIZATIONNAME = "Gianpiero Spinelli"; 104 | TargetAttributes = { 105 | D657799725398F950054F5C5 = { 106 | CreatedOnToolsVersion = 11.1; 107 | }; 108 | }; 109 | }; 110 | buildConfigurationList = D657799325398F950054F5C5 /* Build configuration list for PBXProject "Example" */; 111 | compatibilityVersion = "Xcode 9.3"; 112 | developmentRegion = en; 113 | hasScannedForEncodings = 0; 114 | knownRegions = ( 115 | en, 116 | Base, 117 | ); 118 | mainGroup = D657798F25398F950054F5C5; 119 | packageReferences = ( 120 | D65779AF25398FB60054F5C5 /* XCRemoteSwiftPackageReference "." */, 121 | ); 122 | productRefGroup = D657799925398F950054F5C5 /* Products */; 123 | projectDirPath = ""; 124 | projectRoot = ""; 125 | targets = ( 126 | D657799725398F950054F5C5 /* Example */, 127 | ); 128 | }; 129 | /* End PBXProject section */ 130 | 131 | /* Begin PBXResourcesBuildPhase section */ 132 | D657799625398F950054F5C5 /* Resources */ = { 133 | isa = PBXResourcesBuildPhase; 134 | buildActionMask = 2147483647; 135 | files = ( 136 | D65779A825398F950054F5C5 /* LaunchScreen.storyboard in Resources */, 137 | D65779A525398F950054F5C5 /* Assets.xcassets in Resources */, 138 | D65779A325398F950054F5C5 /* Main.storyboard in Resources */, 139 | ); 140 | runOnlyForDeploymentPostprocessing = 0; 141 | }; 142 | /* End PBXResourcesBuildPhase section */ 143 | 144 | /* Begin PBXSourcesBuildPhase section */ 145 | D657799425398F950054F5C5 /* Sources */ = { 146 | isa = PBXSourcesBuildPhase; 147 | buildActionMask = 2147483647; 148 | files = ( 149 | D65779A025398F950054F5C5 /* ViewController.swift in Sources */, 150 | D657799C25398F950054F5C5 /* AppDelegate.swift in Sources */, 151 | D657799E25398F950054F5C5 /* SceneDelegate.swift in Sources */, 152 | ); 153 | runOnlyForDeploymentPostprocessing = 0; 154 | }; 155 | /* End PBXSourcesBuildPhase section */ 156 | 157 | /* Begin PBXVariantGroup section */ 158 | D65779A125398F950054F5C5 /* Main.storyboard */ = { 159 | isa = PBXVariantGroup; 160 | children = ( 161 | D65779A225398F950054F5C5 /* Base */, 162 | ); 163 | name = Main.storyboard; 164 | sourceTree = ""; 165 | }; 166 | D65779A625398F950054F5C5 /* LaunchScreen.storyboard */ = { 167 | isa = PBXVariantGroup; 168 | children = ( 169 | D65779A725398F950054F5C5 /* Base */, 170 | ); 171 | name = LaunchScreen.storyboard; 172 | sourceTree = ""; 173 | }; 174 | /* End PBXVariantGroup section */ 175 | 176 | /* Begin XCBuildConfiguration section */ 177 | D65779AA25398F950054F5C5 /* Debug */ = { 178 | isa = XCBuildConfiguration; 179 | buildSettings = { 180 | ALWAYS_SEARCH_USER_PATHS = NO; 181 | CLANG_ANALYZER_NONNULL = YES; 182 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 183 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 184 | CLANG_CXX_LIBRARY = "libc++"; 185 | CLANG_ENABLE_MODULES = YES; 186 | CLANG_ENABLE_OBJC_ARC = YES; 187 | CLANG_ENABLE_OBJC_WEAK = YES; 188 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 189 | CLANG_WARN_BOOL_CONVERSION = YES; 190 | CLANG_WARN_COMMA = YES; 191 | CLANG_WARN_CONSTANT_CONVERSION = YES; 192 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 193 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 194 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 195 | CLANG_WARN_EMPTY_BODY = YES; 196 | CLANG_WARN_ENUM_CONVERSION = YES; 197 | CLANG_WARN_INFINITE_RECURSION = YES; 198 | CLANG_WARN_INT_CONVERSION = YES; 199 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 200 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 201 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 202 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 203 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 204 | CLANG_WARN_STRICT_PROTOTYPES = YES; 205 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 206 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 207 | CLANG_WARN_UNREACHABLE_CODE = YES; 208 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 209 | COPY_PHASE_STRIP = NO; 210 | DEBUG_INFORMATION_FORMAT = dwarf; 211 | ENABLE_STRICT_OBJC_MSGSEND = YES; 212 | ENABLE_TESTABILITY = YES; 213 | GCC_C_LANGUAGE_STANDARD = gnu11; 214 | GCC_DYNAMIC_NO_PIC = NO; 215 | GCC_NO_COMMON_BLOCKS = YES; 216 | GCC_OPTIMIZATION_LEVEL = 0; 217 | GCC_PREPROCESSOR_DEFINITIONS = ( 218 | "DEBUG=1", 219 | "$(inherited)", 220 | ); 221 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 222 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 223 | GCC_WARN_UNDECLARED_SELECTOR = YES; 224 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 225 | GCC_WARN_UNUSED_FUNCTION = YES; 226 | GCC_WARN_UNUSED_VARIABLE = YES; 227 | IPHONEOS_DEPLOYMENT_TARGET = 13.1; 228 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 229 | MTL_FAST_MATH = YES; 230 | ONLY_ACTIVE_ARCH = YES; 231 | SDKROOT = iphoneos; 232 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 233 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 234 | }; 235 | name = Debug; 236 | }; 237 | D65779AB25398F950054F5C5 /* Release */ = { 238 | isa = XCBuildConfiguration; 239 | buildSettings = { 240 | ALWAYS_SEARCH_USER_PATHS = NO; 241 | CLANG_ANALYZER_NONNULL = YES; 242 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 244 | CLANG_CXX_LIBRARY = "libc++"; 245 | CLANG_ENABLE_MODULES = YES; 246 | CLANG_ENABLE_OBJC_ARC = YES; 247 | CLANG_ENABLE_OBJC_WEAK = YES; 248 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 249 | CLANG_WARN_BOOL_CONVERSION = YES; 250 | CLANG_WARN_COMMA = YES; 251 | CLANG_WARN_CONSTANT_CONVERSION = YES; 252 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 253 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 254 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 255 | CLANG_WARN_EMPTY_BODY = YES; 256 | CLANG_WARN_ENUM_CONVERSION = YES; 257 | CLANG_WARN_INFINITE_RECURSION = YES; 258 | CLANG_WARN_INT_CONVERSION = YES; 259 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 260 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 261 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 262 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 263 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 264 | CLANG_WARN_STRICT_PROTOTYPES = YES; 265 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 266 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 267 | CLANG_WARN_UNREACHABLE_CODE = YES; 268 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 269 | COPY_PHASE_STRIP = NO; 270 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 271 | ENABLE_NS_ASSERTIONS = NO; 272 | ENABLE_STRICT_OBJC_MSGSEND = YES; 273 | GCC_C_LANGUAGE_STANDARD = gnu11; 274 | GCC_NO_COMMON_BLOCKS = YES; 275 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 276 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 277 | GCC_WARN_UNDECLARED_SELECTOR = YES; 278 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 279 | GCC_WARN_UNUSED_FUNCTION = YES; 280 | GCC_WARN_UNUSED_VARIABLE = YES; 281 | IPHONEOS_DEPLOYMENT_TARGET = 13.1; 282 | MTL_ENABLE_DEBUG_INFO = NO; 283 | MTL_FAST_MATH = YES; 284 | SDKROOT = iphoneos; 285 | SWIFT_COMPILATION_MODE = wholemodule; 286 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 287 | VALIDATE_PRODUCT = YES; 288 | }; 289 | name = Release; 290 | }; 291 | D65779AD25398F950054F5C5 /* Debug */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 295 | CODE_SIGN_STYLE = Automatic; 296 | DEVELOPMENT_TEAM = SEGQ3259G7; 297 | INFOPLIST_FILE = Example/Info.plist; 298 | LD_RUNPATH_SEARCH_PATHS = ( 299 | "$(inherited)", 300 | "@executable_path/Frameworks", 301 | ); 302 | PRODUCT_BUNDLE_IDENTIFIER = com.gianpispi.Example; 303 | PRODUCT_NAME = "$(TARGET_NAME)"; 304 | SWIFT_VERSION = 5.0; 305 | TARGETED_DEVICE_FAMILY = "1,2"; 306 | }; 307 | name = Debug; 308 | }; 309 | D65779AE25398F950054F5C5 /* Release */ = { 310 | isa = XCBuildConfiguration; 311 | buildSettings = { 312 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 313 | CODE_SIGN_STYLE = Automatic; 314 | DEVELOPMENT_TEAM = SEGQ3259G7; 315 | INFOPLIST_FILE = Example/Info.plist; 316 | LD_RUNPATH_SEARCH_PATHS = ( 317 | "$(inherited)", 318 | "@executable_path/Frameworks", 319 | ); 320 | PRODUCT_BUNDLE_IDENTIFIER = com.gianpispi.Example; 321 | PRODUCT_NAME = "$(TARGET_NAME)"; 322 | SWIFT_VERSION = 5.0; 323 | TARGETED_DEVICE_FAMILY = "1,2"; 324 | }; 325 | name = Release; 326 | }; 327 | /* End XCBuildConfiguration section */ 328 | 329 | /* Begin XCConfigurationList section */ 330 | D657799325398F950054F5C5 /* Build configuration list for PBXProject "Example" */ = { 331 | isa = XCConfigurationList; 332 | buildConfigurations = ( 333 | D65779AA25398F950054F5C5 /* Debug */, 334 | D65779AB25398F950054F5C5 /* Release */, 335 | ); 336 | defaultConfigurationIsVisible = 0; 337 | defaultConfigurationName = Release; 338 | }; 339 | D65779AC25398F950054F5C5 /* Build configuration list for PBXNativeTarget "Example" */ = { 340 | isa = XCConfigurationList; 341 | buildConfigurations = ( 342 | D65779AD25398F950054F5C5 /* Debug */, 343 | D65779AE25398F950054F5C5 /* Release */, 344 | ); 345 | defaultConfigurationIsVisible = 0; 346 | defaultConfigurationName = Release; 347 | }; 348 | /* End XCConfigurationList section */ 349 | 350 | /* Begin XCRemoteSwiftPackageReference section */ 351 | D65779AF25398FB60054F5C5 /* XCRemoteSwiftPackageReference "." */ = { 352 | isa = XCRemoteSwiftPackageReference; 353 | repositoryURL = ../; 354 | requirement = { 355 | branch = master; 356 | kind = branch; 357 | }; 358 | }; 359 | /* End XCRemoteSwiftPackageReference section */ 360 | 361 | /* Begin XCSwiftPackageProductDependency section */ 362 | D65779B025398FB60054F5C5 /* Bauletto */ = { 363 | isa = XCSwiftPackageProductDependency; 364 | package = D65779AF25398FB60054F5C5 /* XCRemoteSwiftPackageReference "." */; 365 | productName = Bauletto; 366 | }; 367 | /* End XCSwiftPackageProductDependency section */ 368 | }; 369 | rootObject = D657799025398F950054F5C5 /* Project object */; 370 | } 371 | -------------------------------------------------------------------------------- /Sources/Bauletto/Bauletto.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BaulettoView.swift 3 | // 4 | // 5 | // Created by Gianpiero Spinelli on 05/03/2020. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | internal class BaulettoView: UIView { 12 | private var stackView: UIStackView = UIStackView() 13 | private var iconView: UIImageView = UIImageView() 14 | private var containerView: UIVisualEffectView = UIVisualEffectView() 15 | private var titleLabel: UILabel = { 16 | let l = UILabel() 17 | l.numberOfLines = 1 18 | return l 19 | }() 20 | 21 | private var viewTranslation = CGPoint(x: 0, y: 0) 22 | 23 | /// Show time duration, seconds before the banner goes off. 24 | public var dismissMode: BaulettoDismissMode = .automatic 25 | 26 | public var fadeInAnimation: TimeInterval? = 1 27 | 28 | /// Icon that goes at the left of the text 29 | private var icon: UIImage? { 30 | didSet { 31 | self.iconView.image = icon 32 | } 33 | } 34 | 35 | /// Text that goes at the right of the image 36 | private var title: String? = "It works" { 37 | didSet { 38 | self.titleLabel.text = title 39 | } 40 | } 41 | 42 | /// Tint color for icon and 43 | open override var tintColor: UIColor! { 44 | didSet { 45 | self.iconView.tintColor = tintColor 46 | self.titleLabel.textColor = tintColor 47 | } 48 | } 49 | 50 | /// Style of the background UIVisualEffectView 51 | private var backgroundStyle: UIBlurEffect.Style! { 52 | didSet { 53 | self.containerView.effect = UIBlurEffect(style: backgroundStyle) 54 | } 55 | } 56 | 57 | /// Action that needs to be performed when tapping Bauletto view 58 | private var action: (() -> Void)? = nil 59 | 60 | fileprivate override init(frame: CGRect) { 61 | super.init(frame: frame) 62 | 63 | initialize() 64 | } 65 | 66 | required public init?(coder: NSCoder) { 67 | super.init(coder: coder) 68 | 69 | initialize() 70 | } 71 | 72 | /// Function that adds all the subviews to the view - remember to call the super.initialize() when override it. 73 | open func initialize() { 74 | if #available(iOS 13, *) { 75 | tintColor = .secondaryLabel 76 | backgroundStyle = .systemChromeMaterial 77 | icon = nil 78 | } else { 79 | tintColor = .darkGray 80 | backgroundStyle = .regular 81 | } 82 | 83 | titleLabel.text = title 84 | iconView.image = icon 85 | 86 | stackView.spacing = 10 87 | stackView.axis = .horizontal 88 | stackView.distribution = .fillProportionally 89 | 90 | stackView.addArrangedSubview(iconView) 91 | stackView.addArrangedSubview(titleLabel) 92 | 93 | containerView.contentView.addSubview(stackView) 94 | addSubview(containerView) 95 | 96 | stackView.translatesAutoresizingMaskIntoConstraints = false 97 | containerView.translatesAutoresizingMaskIntoConstraints = false 98 | 99 | NSLayoutConstraint.activate([ 100 | stackView.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 15), 101 | stackView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 20), 102 | stackView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -15), 103 | stackView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -20), 104 | 105 | containerView.topAnchor.constraint(equalTo: topAnchor), 106 | containerView.leadingAnchor.constraint(equalTo: leadingAnchor), 107 | containerView.bottomAnchor.constraint(equalTo: bottomAnchor), 108 | containerView.trailingAnchor.constraint(equalTo: trailingAnchor), 109 | ]) 110 | 111 | self.containerView.isUserInteractionEnabled = true 112 | 113 | let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTapAction)) 114 | 115 | self.containerView.addGestureRecognizer(gestureRecognizer) 116 | 117 | addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handleDismiss(sender:)))) 118 | } 119 | 120 | @objc private func handleTapAction() { 121 | action?() 122 | } 123 | 124 | public func update(withSettings settings: BaulettoSettings?) { 125 | self.icon = settings?.icon 126 | 127 | if let settings = settings, settings.icon == nil { 128 | stackView.removeArrangedSubview(iconView) 129 | } 130 | 131 | self.title = settings?.title ?? self.title 132 | self.tintColor = settings?.tintColor ?? self.tintColor 133 | self.backgroundStyle = settings?.backgroundStyle ?? self.backgroundStyle 134 | self.dismissMode = settings?.dismissMode ?? self.dismissMode 135 | self.action = settings?.action 136 | self.fadeInAnimation = settings?.fadeInDuration 137 | self.titleLabel.font = settings?.font 138 | } 139 | 140 | public func animateIcon() { 141 | iconView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01) 142 | 143 | UIView.animate(withDuration: fadeInAnimation ?? 1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: .curveEaseInOut, animations: { 144 | self.iconView.transform = .identity 145 | }, completion: nil) 146 | } 147 | 148 | public override func layoutSubviews() { 149 | super.layoutSubviews() 150 | 151 | containerView.layer.cornerRadius = min(frame.size.height, frame.size.width) / 2 152 | containerView.layer.masksToBounds = true 153 | 154 | layer.shadowOpacity = 0.4 155 | layer.shadowColor = UIColor.black.withAlphaComponent(0.4).cgColor 156 | layer.shadowOffset = CGSize.zero 157 | layer.shadowRadius = 7 158 | } 159 | } 160 | 161 | extension BaulettoView { 162 | @objc func handleDismiss(sender: UIPanGestureRecognizer) { 163 | switch sender.state { 164 | case .changed: 165 | viewTranslation = sender.translation(in: self) 166 | UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 1, options: .curveEaseOut, animations: { 167 | self.transform = CGAffineTransform(translationX: 0, y: self.viewTranslation.y) 168 | }) 169 | case .ended: 170 | print(viewTranslation.y) 171 | 172 | if viewTranslation.y > 10 { 173 | UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 1, options: .curveEaseOut, animations: { 174 | self.transform = .identity 175 | }) 176 | } else { 177 | Bauletto.hide() 178 | } 179 | default: 180 | break 181 | } 182 | } 183 | } 184 | 185 | public class Bauletto { 186 | public enum QueuePosition { 187 | case beginning, end 188 | } 189 | 190 | fileprivate var bannerView: BaulettoView? = nil 191 | fileprivate var timer: Timer? = nil 192 | 193 | private var queue: [BaulettoSettings?] = [] 194 | 195 | fileprivate func getBannerView() -> BaulettoView { 196 | let bannerView = BaulettoView() 197 | return bannerView 198 | } 199 | 200 | /// - `Banner` shared instance 201 | public static var shared = Bauletto() 202 | 203 | /// Currently shown Bauletto View 204 | public var currentBanner: UIView? { 205 | return bannerView 206 | } 207 | 208 | /// Flag to handle the slideIn animation on showup. By default it is connected to the Accessibility reduce motion setting. 209 | public var animated: Bool = !UIAccessibility.isReduceMotionEnabled 210 | 211 | /// Getting the key window of the current app. 212 | /// Returns 'UIWindow'. 213 | private var keyWindow: UIWindow? { 214 | if #available(iOS 13.0, *), 215 | let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene, 216 | let window = scene.windows.first(where: { $0.isKeyWindow }) { 217 | return window 218 | } 219 | return UIApplication.shared.delegate?.window ?? nil 220 | } 221 | 222 | /// Shows the banner view 223 | /// - Parameters: 224 | /// - settings: BannerSettings which sets the banner's appearance (eg. tintColor, icon...) 225 | /// - animated: Flag to handle the slideIn animation on showup. It overrides the shared `animated` value. 226 | /// - queuePosition: Position in the queue. Added at the end by default. 227 | public static func show(withSettings settings: BaulettoSettings?, _ animated: Bool? = nil, queuePosition: QueuePosition = .end) { 228 | if let animated = animated { 229 | shared.animated = animated 230 | } 231 | 232 | shared.addToQueue(withSettings: settings, position: queuePosition) 233 | shared.showNext() 234 | } 235 | 236 | private static func showBannerView(withSettings settings: BaulettoSettings?) { 237 | shared.bannerView = shared.getBannerView() 238 | shared.bannerView?.update(withSettings: settings) 239 | 240 | guard let window = shared.keyWindow, let bannerView = shared.bannerView else { return } 241 | 242 | window.addSubview(bannerView) 243 | 244 | bannerView.translatesAutoresizingMaskIntoConstraints = false 245 | 246 | var topConstant: CGFloat 247 | if #available(iOS 11, *) { 248 | topConstant = window.safeAreaInsets.top + 15 249 | } else { 250 | topConstant = 15 251 | } 252 | 253 | NSLayoutConstraint.activate([ 254 | bannerView.topAnchor.constraint(equalTo: window.topAnchor, constant: topConstant), 255 | bannerView.centerXAnchor.constraint(equalTo: window.centerXAnchor), 256 | bannerView.leadingAnchor.constraint(greaterThanOrEqualTo: window.leadingAnchor, constant: 20), 257 | bannerView.trailingAnchor.constraint(lessThanOrEqualTo: window.trailingAnchor, constant: -20), 258 | ]) 259 | 260 | if let style = settings?.hapticStyle { 261 | FeedbackGenerator.generate(withStyle: style) 262 | } 263 | 264 | shared.playFadeInAnimation(animated: shared.animated) { _ in 265 | shared.prepareToHide(bannerView: bannerView) 266 | } 267 | } 268 | 269 | /// Plays fade in animation 270 | private func playFadeInAnimation(animated: Bool, _ completion: ((Bool) -> Void)?) { 271 | guard let window = keyWindow, let bannerView = bannerView else { return } 272 | 273 | if animated { 274 | var y: CGFloat 275 | if #available(iOS 11, *) { 276 | y = -(bannerView.bounds.height + window.safeAreaInsets.top + 10) 277 | } else { 278 | y = -(bannerView.bounds.height + 10) 279 | } 280 | 281 | bannerView.transform = CGAffineTransform(translationX: 0, y: y) 282 | 283 | bannerView.animateIcon() 284 | 285 | UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: [.curveEaseInOut, .allowUserInteraction], animations: { 286 | bannerView.transform = .identity 287 | }, completion: completion) 288 | } else { 289 | bannerView.alpha = 0 290 | 291 | UIView.animate(withDuration: 0.25, animations: { 292 | bannerView.alpha = 1 293 | }, completion: completion) 294 | } 295 | } 296 | 297 | private func prepareToHide(bannerView: BaulettoView) { 298 | if bannerView.dismissMode != .never { 299 | self.timer = Timer.scheduledTimer(timeInterval: bannerView.dismissMode.duration, target: self, selector: #selector(self.hide), userInfo: nil, repeats: false) 300 | } 301 | } 302 | 303 | private func playFadeOutAnimation(animated: Bool, _ completion: ((Bool) -> Void)?) { 304 | guard let window = keyWindow, let bannerView = bannerView else { 305 | completion?(false) 306 | return 307 | } 308 | 309 | UIView.animate(withDuration: 0.25, animations: { 310 | if animated { 311 | var y: CGFloat 312 | if #available(iOS 11, *) { 313 | y = -(bannerView.bounds.height + window.safeAreaInsets.top + 10) 314 | } else { 315 | y = -(bannerView.bounds.height + 10) 316 | } 317 | 318 | bannerView.transform = CGAffineTransform(translationX: 0, y: y) 319 | } else { 320 | bannerView.alpha = 0 321 | } 322 | }, completion: completion) 323 | } 324 | 325 | @objc private func hide() { 326 | Bauletto.hide() 327 | } 328 | 329 | /// Hides the banner view 330 | /// - Parameter animated: Flag to handle the slideOut animation on dismiss. By default it is connected to the Accessibility reduce motion setting. 331 | /// - Parameter completion: Flag to handle the slideOut animation on hide. It overrides the shared `animated` value. 332 | public static func hide(_ animated: Bool? = nil, completion: (() -> ())? = nil) { 333 | if let animated = animated { 334 | shared.animated = animated 335 | } 336 | 337 | func hideProgressHud() { 338 | shared.bannerView?.removeFromSuperview() 339 | shared.bannerView = nil 340 | } 341 | 342 | shared.timer?.invalidate() 343 | 344 | DispatchQueue.main.async { 345 | shared.playFadeOutAnimation(animated: shared.animated, { success in 346 | guard success else { 347 | completion?() 348 | return 349 | } 350 | 351 | hideProgressHud() 352 | 353 | shared.queue.removeFirst() 354 | 355 | if shared.queue.isEmpty { 356 | DispatchQueue.main.async { 357 | completion?() 358 | } 359 | } else { 360 | shared.showNext() 361 | } 362 | }) 363 | } 364 | } 365 | 366 | // MARK: - QUEUE 367 | private func addToQueue(withSettings settings: BaulettoSettings?, position: QueuePosition) { 368 | switch position { 369 | case .beginning: 370 | queue.insert(settings, at: 0) 371 | case .end: 372 | queue.append(settings) 373 | } 374 | } 375 | 376 | private func showNext() { 377 | guard 378 | let next = queue.first, 379 | bannerView?.superview == nil else { 380 | return 381 | } 382 | Bauletto.showBannerView(withSettings: next) 383 | } 384 | 385 | public func forceShowNext() { 386 | guard queue.first != nil else { return } 387 | Bauletto.hide(completion: nil) 388 | } 389 | 390 | public func removeBannersInQueue() { 391 | queue.removeAll() 392 | } 393 | } 394 | --------------------------------------------------------------------------------