### Install SwiftMessages via Carthage Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Add this line to your Cartfile to integrate SwiftMessages using Carthage, a decentralized dependency manager for iOS projects. After adding, run 'carthage update --platform iOS' in your terminal. ```carthage github "SwiftKickMobile/SwiftMessages" ``` -------------------------------- ### Presenting View Controllers Globally with WindowViewController Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/ViewControllers.md This example shows how to present a view controller on top of all other controllers by using `WindowViewController` as the source for `SwiftMessagesSegue`. It also demonstrates how to configure the presentation context, such as specifying window properties, using `SwiftMessages.Config`. ```Swift let destinationVC = ... // make a reference to a destination view controller var config = SwiftMessages.defaultConfig config.presentationContext = .windowScene(...) // specify the window properties let sourceVC = WindowViewController(config: config) let segue = SwiftMessagesSegue(identifier: nil, source: self, destination: destinationVC) segue.perform() ``` -------------------------------- ### Install SwiftMessages via CocoaPods Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Add this line to your Podfile to integrate SwiftMessages using CocoaPods, a dependency manager for iOS projects. After adding, run 'pod install' in your terminal. ```ruby pod 'SwiftMessages' ``` -------------------------------- ### Display Custom SwiftUI Message Imperatively Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md This example demonstrates how to programmatically display a custom SwiftUI message using the `SwiftMessages.show(view:)` API within a button's action closure. It wraps the custom SwiftUI view in a `MessageHostingView`. ```Swift struct DemoView: View { var body: some View { Button("Show message") { let message = DemoMessage(title: "Demo", body: "SwiftUI forever!") let messageView = MessageHostingView(id: message.id, content: DemoMessageView(message: message)) SwiftMessages.show(view: messageView) } } } ``` -------------------------------- ### Configure and Display a MessageView Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Demonstrates how to instantiate, configure, and display a `MessageView` using various customization options. This includes applying themes, adding drop shadows, setting content (title, body, icon), adjusting layout margins, and modifying corner radius for a rich visual presentation. ```Swift // Instantiate a message view from the provided card view layout. SwiftMessages searches for nib // files in the main bundle first, so you can easily copy them into your project and make changes. let view = MessageView.viewFromNib(layout: .cardView) // Theme message elements with the warning style. view.configureTheme(.warning) // Add a drop shadow. view.configureDropShadow() // Set message title, body, and icon. Here, we're overriding the default warning // image with an emoji character. let iconText = ["🤔", "😳", "🙄", "😶"].randomElement()! view.configureContent(title: "Warning", body: "Consider yourself warned.", iconText: iconText) // Increase the external margin around the card. In general, the effect of this setting // depends on how the given layout is constrained to the layout margins. view.layoutMarginAdditions = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20) // Reduce the corner radius (applicable to layouts featuring rounded corners). (view.backgroundView as? CornerRoundingView)?.cornerRadius = 10 // Show the message. SwiftMessages.show(view: view) ``` -------------------------------- ### Configure MessageView Content and Theme in Swift Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Illustrates the use of `MessageView`'s convenience methods, `configureTheme` and `configureContent`, for quickly setting the visual theme, title, body text, and icon of a message. These methods are shortcuts for direct property configuration. ```swift view.configureTheme(.warning, includeHaptic: true) view.configureContent(title: "Warning", body: "Consider yourself warned.", iconText: "🤔") ``` -------------------------------- ### Load MessageView from Bundled Nib Layout Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Demonstrates using the `MessageView.viewFromNib(layout:)` convenience method to instantiate a `MessageView` from one of SwiftMessages' bundled nib layouts. This simplifies the process of using pre-designed message views. ```Swift let view = MessageView.viewFromNib(layout: .cardView) ``` -------------------------------- ### Using configure(layout:) for Basic Presentation Styles Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/ViewControllers.md Shows how to use the `configure(layout:)` shortcut method on `SwiftMessagesSegue` to quickly apply common layout and animation options, mirroring those available in `SwiftMessages.Layout`. ```swift // Configure a bottom card-style presentation segue.configure(layout: .bottomCard) ``` -------------------------------- ### Apply and Override Default SwiftMessages Configuration Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Shows how to set global default configuration options for SwiftMessages, which simplifies consistent styling across an application. It also demonstrates how to use these defaults for new messages or customize them for specific instances by creating a mutable copy. ```Swift SwiftMessages.defaultConfig.presentationStyle = .bottom // Show message with default config. SwiftMessages.show(view: view) // Customize config using the default as a base. var config = SwiftMessages.defaultConfig config.duration = .forever SwiftMessages.show(config: config, view: view) ``` -------------------------------- ### Display a Basic Message with SwiftMessages Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Shows any `UIView` instance as a message using the SwiftMessages library. This is the simplest way to display a custom view, making it visible on screen. ```Swift SwiftMessages.show(view: myView) ``` -------------------------------- ### Programmatic Instantiation and Performance of SwiftMessagesSegue Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/ViewControllers.md This snippet demonstrates how to programmatically create an instance of `SwiftMessagesSegue` and perform it to present a destination view controller. It highlights the flexibility of using the segue without relying on storyboards. ```Swift let destinationVC = ... // make a reference to a destination view controller let segue = SwiftMessagesSegue(identifier: nil, source: self, destination: destinationVC) ... // do any configuration here segue.perform() ``` -------------------------------- ### Display Message with View Provider Closure Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Utilizes the `show(viewProvider:)` variant to ensure that UIKit code for view creation and configuration is executed safely on the main queue. This is a recommended practice for UI operations to prevent threading issues. ```Swift SwiftMessages.show { let view = MessageView.viewFromNib(layout: .cardView) // ... configure the view return view } ``` -------------------------------- ### Customize Message Presentation with SwiftMessages.Config Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Illustrates how to create and modify a `SwiftMessages.Config` struct to control various aspects of message presentation. This includes setting presentation style, context, duration, dim mode, interactive hide gestures, haptic feedback, status bar style, and attaching event listeners for show/hide events. ```Swift var config = SwiftMessages.Config() // Slide up from the bottom. config.presentationStyle = .bottom // Display in a window at the specified window level. config.presentationContext = .window(windowLevel: .statusBar) // Note that, as of iOS 13, it is no longer possible to cover the status bar // regardless of the window level. A workaround is to hide the status bar instead. config.prefersStatusBarHidden = true // Disable the default auto-hiding behavior. config.duration = .forever // Dim the background like a popover view. Hide when the background is tapped. config.dimMode = .gray(interactive: true) // Disable the interactive pan-to-hide gesture. config.interactiveHide = false // Specify haptic feedback (see also MessageView/configureTheme) config.haptic = .success // Specify a status bar style to if the message is displayed directly under the status bar. config.preferredStatusBarStyle = .lightContent // Specify one or more event listeners to respond to show and hide events. config.eventListeners.append() { event in if case .didHide = event { print("yep id=\(String(describing: event.id)") } } SwiftMessages.show(config: config, view: view) ``` -------------------------------- ### Manage Multiple SwiftMessages Instances Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Illustrates how to create and use multiple independent instances of `SwiftMessages` to display more than one message concurrently. It emphasizes that instances must be retained as properties (e.g., in a view controller) to function correctly. ```Swift class SomeViewController: UIViewController { let otherMessages = SwiftMessages() func someMethod() { SwiftMessages.show(...) otherMessages.show(...) } } ``` -------------------------------- ### Load Custom Views from Named Nibs with SwiftMessages Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Illustrates how to use the generic `SwiftMessages.viewFromNib()` methods to instantiate `MessageView` from a specific named nib file or a custom `UIView` subclass from a nib named after the class. This provides flexibility for advanced customization with your own nib-based layouts. ```Swift // Instantiate MessageView from a named nib. let view: MessageView = try! SwiftMessages.viewFromNib(named: "MyCustomNib") // Instantiate MyCustomView from a nib named MyCustomView.nib. let view: MyCustomView = try! SwiftMessages.viewFromNib() ``` -------------------------------- ### MessageView Class Definition and Properties Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Documents the `MessageView` class, a lightweight view that serves as the foundation for all bundled SwiftMessages designs. It details the core optional `@IBOutlet` properties available for displaying various content elements. ```APIDOC class MessageView Properties: titleLabel: UILabel? - The message title. bodyLabel: UILabel? - The body of the message. iconImageView: UIImageView? - An image-based icon. iconLabel: UILabel? - A text-based (emoji) alternative to the image icon. button: UIButton? - An action button. ``` -------------------------------- ### Animator Protocol and Implementations Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Defines the `Animator` protocol, which SwiftMessages uses to manage presentation and dismissal animations. It also describes built-in implementations like `TopBottomAnimation` and `PhysicsAnimation`, and the `PhysicsPanHandler` for dismissal gestures. ```APIDOC protocol Animator - Used for presentation and dismissal animations. - Custom animations can be set via SwiftMessages.PresentationStyle.custom(animator:). Related Components: TopBottomAnimation: Animator - Sliding implementation used by .top and .bottom presentation styles. PhysicsAnimation: Animator - Scaling + opacity implementation used by .center presentation style. - Provides a fun physics-based dismissal gesture. PhysicsPanHandler - Provides the physics-based dismissal gesture for PhysicsAnimation. ``` -------------------------------- ### AccessibleMessage Protocol Reference Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md The `AccessibleMessage` protocol is designed for custom views to implement proper accessibility support, ensuring they integrate well with VoiceOver and other assistive technologies. ```APIDOC protocol AccessibleMessage { // Purpose: Provides an interface for custom views to define their accessibility behavior. // Implementations should ensure VoiceOver and other assistive technologies can properly interpret the message content. } ``` -------------------------------- ### Configuring SwiftMessagesSegue in prepare(for:sender:) Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/ViewControllers.md Illustrates an alternative method for configuring `SwiftMessagesSegue` by down-casting the segue within the `prepare(for:sender:)` method of the presenting view controller. This allows for dynamic configuration based on the context of the segue. ```swift override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let segue = segue as? SwiftMessagesSegue { segue.configure(layout: .bottomCard) segue.dimMode = .blur(style: .dark, alpha: 0.9, interactive: true) segue.messageView.configureNoDropShadow() } } ``` -------------------------------- ### BaseView Class Definition Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Documents the `BaseView` class, which serves as the superclass for `MessageView`. It provides a foundation for custom views that require general options not specific to the `MessageView`'s 'title + body + icon + button' design. ```APIDOC class BaseView - Superclass of MessageView. - Provides general options for custom views not specific to MessageView's design. ``` -------------------------------- ### Define Custom SwiftUI Message View and Data Model Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md This snippet defines a simple `Identifiable` data model (`DemoMessage`) and a corresponding SwiftUI `View` (`DemoMessageView`) that can be used to display custom messages with SwiftMessages. It includes styling for a tab-style appearance. ```Swift struct DemoMessage: Identifiable { let title: String let body: String var id: String { title + body } } struct DemoMessageView: View { let message: DemoMessage var body: some View { VStack(alignment: .leading) { Text(message.title).font(.system(size: 20, weight: .bold)) Text(message.body) } .multilineTextAlignment(.leading) .padding(30) // This makes the message width greedy .frame(maxWidth: .infinity) .background(.gray) // This makes a tab-style view where the bottom corners are rounded and // the view's background extends to the top edge. .mask( UnevenRoundedRectangle(bottomLeadingRadius: 15, bottomTrailingRadius: 15) // This causes the background to extend into the safe area to the screen edge. .edgesIgnoringSafeArea(.top) ) } } ``` -------------------------------- ### Customizing SwiftMessagesSegue Presentation Options Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/ViewControllers.md Demonstrates how to directly set various `SwiftMessages.Config` options that are mirrored on `SwiftMessagesSegue`, allowing for fine-grained control over interactive dismissal, dimming behavior, and presentation style. ```swift // Turn off interactive dismiss segue.interactiveHide = false // Enable dimmed background with tap-to-dismiss segue.dimMode = .gray(interactive: true) // Specify the animation and positioning segue.presentationStyle = .bottom ``` -------------------------------- ### Subclassing SwiftMessagesSegue for Custom Configuration Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/ViewControllers.md Demonstrates the recommended approach to configure `SwiftMessagesSegue` by creating a custom subclass and applying configurations within its `init(identifier:source:destination:)` method. This allows for reusable and named segue types in Interface Builder. ```swift class VeryNiceSegue: SwiftMessagesSegue { override public init(identifier: String?, source: UIViewController, destination: UIViewController) { super.init(identifier: identifier, source: source, destination: destination) configure(layout: .bottomCard) dimMode = .blur(style: .dark, alpha: 0.9, interactive: true) messageView.configureNoDropShadow() } } ``` -------------------------------- ### Conform Data Model to MessageViewConvertible Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md To simplify the usage of the `swiftMessage()` modifier for purely data-driven messages, this extension makes `DemoMessage` conform to the `MessageViewConvertible` protocol by providing a method to convert itself into a `DemoMessageView`. ```Swift extension DemoMessage: MessageViewConvertible { func asMessageView() -> DemoMessageView { DemoMessageView(message: self) } } ``` -------------------------------- ### Configure Keyboard Tracking for SwiftMessages Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Demonstrates how to configure `SwiftMessages.defaultConfig` to use `KeyboardTrackingView` for automatic keyboard avoidance, ensuring message views slide up when the keyboard appears. This helps prevent the keyboard from obscuring messages. ```Swift var config = SwiftMessages.defaultConfig config.keyboardTrackingView = KeyboardTrackingView() ``` -------------------------------- ### MarginAdjustable Protocol Definition Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Documents the `MarginAdjustable` protocol, adopted by `BaseView`. This protocol allows SwiftMessages to take ownership of a view's layout margins, ensuring optimal spacing and alignment across various presentation contexts. ```APIDOC protocol MarginAdjustable - Adopted by BaseView. - Allows SwiftMessages to manage a view's layout margins for ideal spacing across presentation contexts. ``` -------------------------------- ### Handle Button and View Taps on MessageView in Swift Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Shows how to assign block-based tap handlers to the `MessageView`'s action button and the view itself. These handlers allow for custom actions, such as hiding the message, when the respective elements are tapped. ```swift // Hide when button tapped messageView.buttonTapHandler = { _ in SwiftMessages.hide() } // Hide when message view tapped messageView.tapHandler = { _ in SwiftMessages.hide() } ``` -------------------------------- ### Simplified State-based Message Display with MessageViewConvertible Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md After the data model conforms to `MessageViewConvertible`, the `swiftMessage()` modifier can be used without a view builder closure, leading to cleaner code for displaying messages based on state changes. ```Swift struct DemoView: View { @State var message: DemoMessage? var body: some View { Button("Show message") { message = DemoMessage(title: "Demo", body: "SwiftUI forever!") } .swiftMessage(message: $message) } } ``` -------------------------------- ### CornerRoundingView Class Definition Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Documents the `CornerRoundingView` class, a specialized view used by messages for applying smooth corner rounding (squircles) to all or a subset of corners. It includes an option to dynamically round only the leading corners. ```APIDOC class CornerRoundingView Properties: roundsLeadingCorners: Bool - Option to dynamically round only the leading corners of the view when presented from top or bottom. ``` -------------------------------- ### Configuring messageView Properties on SwiftMessagesSegue Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/ViewControllers.md Explains how to access and customize properties of the `messageView` (an instance of `BaseView`) through `SwiftMessagesSegue`. This includes adjusting layout margins, collapsing margins, adding drop shadows, and specifying view containment. ```swift // Increase the internal layout margins. With the `.background` containment option, // the margin additions specify the outer margins around `messageView.backgroundView`. segue.messageView.layoutMarginAdditions = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20) // Collapse layout margin edges that encroach on non-zero safe area insets. messageView.collapseLayoutMarginAdditions = true // Add a default drop shadow. segue.messageView.configureDropShadow() // Indicate that the view controller's view should be installed // as the `backgroundView` of `messageView`. segue.containment = .background ``` -------------------------------- ### Display Custom SwiftUI Message with State-based Modifier Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md This snippet illustrates a state-driven approach to displaying messages using the `swiftMessage()` view modifier. The message is shown or hidden based on the state of an optional `DemoMessage` variable, similar to SwiftUI's `.sheet()` modifier. ```Swift struct DemoView: View { @State var message: DemoMessage? var body: some View { Button("Show message") { message = DemoMessage(title: "Demo", body: "SwiftUI forever!") } .swiftMessage(message: $message) { message in DemoMessageView(message: message) } } } ``` -------------------------------- ### Retrieve Current or Queued SwiftMessages by ID Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Shows how to retrieve references to message views that are currently being shown, hidden, or queued, using their unique identifiers. These APIs are useful for updating messages dynamically based on application events without needing to maintain temporary references. ```Swift // Get a message view with the given ID if it is currently // being shown or hidden. if let view = SwiftMessages.current(id: "some id") { ... } // Get a message view with the given ID if is it currently // queued to be shown. if let view = SwiftMessages.queued(id: "some id") { ... } // Get a message view with the given ID if it is currently being // shown, hidden or in the queue to be shown. if let view = SwiftMessages.currentOrQueued(id: "some id") { ... } ``` -------------------------------- ### Dismissing a Modally Presented View Controller Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/ViewControllers.md This code illustrates the standard UIKit method for dismissing a view controller that was presented modally. It's a common pattern used after a segue has performed its presentation. ```Swift dismiss(animated: true, completion: nil) ``` -------------------------------- ### Adjust Pause Duration Between SwiftMessages Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Sets the global pause duration in seconds between consecutive messages shown by SwiftMessages. This controls the display speed of queued messages, allowing for a smoother user experience. ```Swift SwiftMessages.pauseBetweenMessages = 1.0 ``` -------------------------------- ### Programmatically Hide SwiftMessages Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Provides various methods to programmatically hide messages, including hiding the currently displayed message, clearing the entire message queue, hiding specific identifiable messages by ID, and using a counted hide mechanism for messages shown from multiple code paths. ```Swift // Hide the current message. SwiftMessages.hide() // Or hide the current message and clear the queue. SwiftMessages.hideAll() // Or for a view that implements `Identifiable`: SwiftMessages.hide(id: someId) // Or hide when the number of calls to show() and hideCounted(id:) for a // given message ID are equal. This can be useful for messages that may be // shown from multiple code paths to ensure that all paths are ready to hide. SwiftMessages.hideCounted(id: someId) ``` -------------------------------- ### Hide MessageView Elements in Swift Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/README.md Demonstrates the correct way to remove an element from the `MessageView`'s visible hierarchy by setting its `isHidden` property to `true`. This ensures the element is properly hidden without attempting to set its outlet to `nil`. ```swift view.titleLabel.isHidden = true ``` -------------------------------- ### Assign KeyboardTrackingView to SwiftMessagesSegue Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/ViewControllers.md Demonstrates how to assign an instance of `KeyboardTrackingView` to the `keyboardTrackingView` property of a `SwiftMessagesSegue` object. This enables the message view presented by the segue to automatically adjust its position to avoid the software keyboard. ```Swift segue.keyboardTrackingView = KeyboardTrackingView() ``` -------------------------------- ### Adjusting containerView Corner Radius on SwiftMessagesSegue Source: https://github.com/swiftkickmobile/swiftmessages/blob/master/ViewControllers.md Shows how to modify the `cornerRadius` property of the `containerView` (an instance of `ViewControllerContainerView`) accessible via `SwiftMessagesSegue`, enabling custom corner rounding for the presented view controller's container. ```swift // Change the corner radius segue.containerView.cornerRadius = 20 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.