-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add HTML view stub * Add HTML display functionality * Fix comment * Update InAppMessageEnvironment to hold extensions wrapper object * Add InAppMessageExtensions wrapper object * Add additional HTML examples * Remove unnecessary print statement * Add default HTML theme * Add InAppMessageWebView * Add BeveledLoadingView * Add HTMLView * Update MediaView to check for when image loader is available * Add InAppMessageViewUtils for shared functionality between in-app layouts * Update FullScreenView to use shared in-app message utils * pbxproj changes * Clean-up * Padding * Pass InAppMessageNativeBridgeExtension into HTML InAppMessageEnvironment * Remove tvOS and watchOS checks in AirshipAutomationSwift * Make InAppMessageExtensions wrapper into a struct * Add additional testing examples adn update existing ones * Update modal default theme * Make InAppMessageWebView transparent * Update view utilities for sizing Modal and HTML views * Make HTMLView default to clear when no background color is specified * Update button group to allow relative button sizing * Wire up ModalView display * Add ModalView * Make footer a button instead of media * pbxproj changes * Add jurassic park font * Update examples to use jurassic park font * Rename ModalView to InAppModalMessageView to prevent pod lint issue * Fix warnings * Fix ParentClampingResize modifier * Fix modal theming * Add @mainactor to displayModal and displayHTML --------- Co-authored-by: crow <[email protected]>
- Loading branch information
Showing
24 changed files
with
889 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
Airship/AirshipAutomationSwift/Source/InAppMessage/View/InAppMessageModalView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* Copyright Airship and Contributors */ | ||
|
||
import SwiftUI | ||
|
||
#if canImport(AirshipCore) | ||
import AirshipCore | ||
#endif | ||
|
||
struct InAppMessageModalView: View { | ||
@EnvironmentObject var environment: InAppMessageEnvironment | ||
let displayContent: InAppMessageDisplayContent.Modal | ||
|
||
@Environment(\.orientation) var orientation | ||
|
||
private var padding: EdgeInsets { | ||
environment.theme.modalTheme.additionalPadding | ||
} | ||
|
||
private var headerTheme: TextTheme { | ||
environment.theme.modalTheme.headerTheme | ||
} | ||
|
||
private var bodyTheme: TextTheme { | ||
environment.theme.modalTheme.bodyTheme | ||
} | ||
|
||
private var mediaTheme: MediaTheme { | ||
environment.theme.modalTheme.mediaTheme | ||
} | ||
|
||
private var dismissIconResource: String { | ||
environment.theme.modalTheme.dismissIconResource | ||
} | ||
|
||
private var maxHeight: CGFloat { | ||
CGFloat(environment.theme.modalTheme.maxHeight) | ||
} | ||
|
||
private var maxWidth: CGFloat { | ||
CGFloat(environment.theme.modalTheme.maxWidth) | ||
} | ||
|
||
@ViewBuilder | ||
private var headerView: some View { | ||
let theme = environment.theme.fullScreenTheme | ||
|
||
if let heading = displayContent.heading { | ||
TextView(textInfo: heading, textTheme:headerTheme) | ||
.padding(theme.headerTheme.additionalPadding) | ||
.padding(headerTheme.additionalPadding) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
private var bodyView: some View { | ||
if let body = displayContent.body { | ||
TextView(textInfo: body, textTheme:bodyTheme) | ||
.applyTextTheme(headerTheme) | ||
.padding(bodyTheme.additionalPadding) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
private var mediaView: some View { | ||
if let media = displayContent.media { | ||
MediaView(mediaInfo: media, mediaTheme: mediaTheme, imageLoader: environment.imageLoader) | ||
.padding(.horizontal, -mediaTheme.additionalPadding.leading).padding(mediaTheme.additionalPadding) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
private var buttonsView: some View { | ||
if let buttons = displayContent.buttons, let layout = displayContent.buttonLayoutType, !buttons.isEmpty { | ||
ButtonGroup(layout: layout, | ||
buttons: buttons) | ||
.environmentObject(environment) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
private var footerButton: some View { | ||
if let footer = displayContent.footer { | ||
ButtonView(buttonInfo: footer) | ||
.frame(height:Theme.defaultFooterHeight) | ||
.environmentObject(environment) | ||
} | ||
} | ||
|
||
private var orientationChangePublisher = NotificationCenter.default | ||
.publisher(for: UIDevice.orientationDidChangeNotification) | ||
.makeConnectable() | ||
.autoconnect() | ||
|
||
init(displayContent: InAppMessageDisplayContent.Modal) { | ||
self.displayContent = displayContent | ||
} | ||
|
||
var body: some View { | ||
ZStack { | ||
ScrollView { | ||
VStack(spacing:24) { | ||
switch displayContent.template { | ||
case .headerMediaBody: | ||
headerView | ||
mediaView | ||
bodyView | ||
case .headerBodyMedia: | ||
headerView | ||
bodyView | ||
mediaView | ||
case .mediaHeaderBody, .none: /// None should never be hit | ||
mediaView.padding(.top, -padding.top) /// Remove top padding when media is on top | ||
headerView | ||
bodyView | ||
} | ||
|
||
}.padding(padding) | ||
.background(Color.tappableClear) | ||
} | ||
VStack { | ||
Spacer() | ||
VStack(spacing:24) { | ||
buttonsView | ||
footerButton | ||
} | ||
.padding(padding) | ||
.background(displayContent.backgroundColor?.color ?? Color.black) | ||
} | ||
}.addBackground(color: displayContent.backgroundColor?.color ?? Color.black) | ||
.addCloseButton(dismissButtonColor: displayContent.dismissButtonColor?.color ?? Color.white, | ||
dismissIconResource: dismissIconResource, | ||
circleColor: .tappableClear, /// Probably should just do this everywhere and remove circleColor entirely | ||
onUserDismissed: { environment.onUserDismissed() }) | ||
.cornerRadius(displayContent.borderRadius ?? 0) | ||
.parentClampingResize(maxWidth: maxWidth, maxHeight: maxHeight) | ||
.padding(padding) | ||
.addBackground(color: .shadowColor) | ||
} | ||
} |
Oops, something went wrong.