Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/demo/App.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<string>$(APS_ENVIRONMENT)</string>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.onesignal.example.onesignal</string>
<string>group.com.onesignal.sdkdemo.onesignal</string>
</array>
</dict>
</plist>
46 changes: 23 additions & 23 deletions examples/demo/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
E194A3F19072CB17A8F1A12E /* SmsSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmsSection.swift; sourceTree = "<group>"; };
ECAC7EF0B67920F9FEC4F129 /* TagsSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsSection.swift; sourceTree = "<group>"; };
F46DFACB9F304B9374F3C570 /* ToastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastView.swift; sourceTree = "<group>"; };
"TEMP_DEC528CA-1E47-4B0F-AAAF-071417BC60C5" /* Build.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Build.xcconfig; sourceTree = "<group>"; };
"TEMP_2F85E914-D20C-4EA7-A633-D4D6487C35EA" /* Build.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Build.xcconfig; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -591,10 +591,10 @@
path = Support;
sourceTree = "<group>";
};
"TEMP_17E43425-D1F7-4A88-B0A0-C0368CB0E171" /* demo */ = {
"TEMP_915DBED0-7714-4B53-A845-B8138FF5BA7F" /* demo */ = {
isa = PBXGroup;
children = (
"TEMP_DEC528CA-1E47-4B0F-AAAF-071417BC60C5" /* Build.xcconfig */,
"TEMP_2F85E914-D20C-4EA7-A633-D4D6487C35EA" /* Build.xcconfig */,
);
path = demo;
sourceTree = "<group>";
Expand Down Expand Up @@ -968,15 +968,14 @@
/* Begin XCBuildConfiguration section */
0D2EF3911CA89837C30DB0D1 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = "TEMP_DEC528CA-1E47-4B0F-AAAF-071417BC60C5" /* Build.xcconfig */;
baseConfigurationReference = "TEMP_2F85E914-D20C-4EA7-A633-D4D6487C35EA" /* Build.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
DEVELOPMENT_TEAM = 99SW8E36CT;
INFOPLIST_FILE = OneSignalWidget/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 16.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.LA;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.sdkdemo.LA;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
Expand All @@ -986,17 +985,17 @@
};
4A0C935808978B5A7673E412 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = "TEMP_DEC528CA-1E47-4B0F-AAAF-071417BC60C5" /* Build.xcconfig */;
baseConfigurationReference = "TEMP_2F85E914-D20C-4EA7-A633-D4D6487C35EA" /* Build.xcconfig */;
buildSettings = {
APS_ENVIRONMENT = development;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = App.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
DEVELOPMENT_TEAM = 99SW8E36CT;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.sdkdemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_OBJC_BRIDGING_HEADER = "App/App-Bridging-Header.h";
Expand Down Expand Up @@ -1069,17 +1068,17 @@
};
D0E56A85F1C385808720F94B /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = "TEMP_DEC528CA-1E47-4B0F-AAAF-071417BC60C5" /* Build.xcconfig */;
baseConfigurationReference = "TEMP_2F85E914-D20C-4EA7-A633-D4D6487C35EA" /* Build.xcconfig */;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = OneSignalNotificationServiceExtension/OneSignalNotificationServiceExtension.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 99SW8E36CT;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = DL8TF3X4K3;
INFOPLIST_FILE = OneSignalNotificationServiceExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.NSE;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.sdkdemo.NSE;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "Appium Demo - NSE";
Expand All @@ -1091,19 +1090,21 @@
};
EB1CC3A930E09FEBECF9195D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = "TEMP_DEC528CA-1E47-4B0F-AAAF-071417BC60C5" /* Build.xcconfig */;
baseConfigurationReference = "TEMP_2F85E914-D20C-4EA7-A633-D4D6487C35EA" /* Build.xcconfig */;
buildSettings = {
APS_ENVIRONMENT = production;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = App.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 99SW8E36CT;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = DL8TF3X4K3;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.sdkdemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "Appium Demo - Main";
Expand All @@ -1115,18 +1116,18 @@
};
F305A3E63851EE49DA2D190E /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = "TEMP_DEC528CA-1E47-4B0F-AAAF-071417BC60C5" /* Build.xcconfig */;
baseConfigurationReference = "TEMP_2F85E914-D20C-4EA7-A633-D4D6487C35EA" /* Build.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 99SW8E36CT;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = DL8TF3X4K3;
INFOPLIST_FILE = OneSignalWidget/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 16.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.LA;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.sdkdemo.LA;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "Appium Demo - Live Activity";
Expand All @@ -1138,14 +1139,13 @@
};
F5FD25168D9B32A08A468069 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = "TEMP_DEC528CA-1E47-4B0F-AAAF-071417BC60C5" /* Build.xcconfig */;
baseConfigurationReference = "TEMP_2F85E914-D20C-4EA7-A633-D4D6487C35EA" /* Build.xcconfig */;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = OneSignalNotificationServiceExtension/OneSignalNotificationServiceExtension.entitlements;
DEVELOPMENT_TEAM = 99SW8E36CT;
INFOPLIST_FILE = OneSignalNotificationServiceExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.NSE;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.sdkdemo.NSE;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app uses your location to personalize notifications and content even when the app is in the background.</string>
<key>OneSignal_app_groups_key</key>
<string>group.com.onesignal.example.onesignal</string>
<string>group.com.onesignal.sdkdemo.onesignal</string>
<key>NSSupportsLiveActivities</key>
<true/>
<key>NSSupportsLiveActivitiesFrequentUpdates</key>
Expand Down
45 changes: 45 additions & 0 deletions examples/demo/App/Views/Components/ActionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,48 @@ struct ActionButton: View {
}
}
}

/// Lays out section buttons two per row. An odd last button spans both
/// columns. Conditionally hidden buttons drop out, so the grid reflows.
struct ButtonGrid: Layout {
var spacing: CGFloat = OS.Spacing.cardGap

func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
let width = proposal.replacingUnspecifiedDimensions().width
let heights = rowHeights(width: width, subviews: subviews)
let gaps = spacing * CGFloat(max(heights.count - 1, 0))
return CGSize(width: width, height: heights.reduce(0, +) + gaps)
}

func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
let heights = rowHeights(width: bounds.width, subviews: subviews)
var rowTop = bounds.minY
for (row, height) in heights.enumerated() {
for (column, frame) in cellFrames(row: row, width: bounds.width, count: subviews.count).enumerated() {
subviews[row * 2 + column].place(
at: CGPoint(x: bounds.minX + frame.minX, y: rowTop),
proposal: ProposedViewSize(width: frame.width, height: height)
)
}
rowTop += height + spacing
}
}

private func rowHeights(width: CGFloat, subviews: Subviews) -> [CGFloat] {
stride(from: 0, to: subviews.count, by: 2).map { first in
cellFrames(row: first / 2, width: width, count: subviews.count)
.enumerated()
.map { column, frame in
subviews[first + column].sizeThatFits(ProposedViewSize(width: frame.width, height: nil)).height
}
.max() ?? 0
}
}

/// Horizontal extent of each cell in `row`; one full-width cell for an odd last button.
private func cellFrames(row: Int, width: CGFloat, count: Int) -> [(minX: CGFloat, width: CGFloat)] {
if row * 2 + 1 == count { return [(0, width)] }
let half = (width - spacing) / 2
return [(0, half), (half + spacing, half)]
}
}
2 changes: 1 addition & 1 deletion examples/demo/App/Views/Components/AddItemDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import SwiftUI

/// Reusable centered dialog for adding items with one or two text fields.
/// Reusable dialog for adding items with one or two text fields.
struct AddItemDialog: View {
let itemType: AddItemType
let onAdd: (String, String) -> Void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import SwiftUI

/// Centered dialog for composing a custom push notification (title + body).
/// Dialog for composing a custom push notification (title + body).
struct CustomNotificationDialog: View {
let onSend: (String, String) -> Void
let onCancel: () -> Void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import SwiftUI

/// Centered dialog that adds multiple key/value pairs at once
/// Dialog that adds multiple key/value pairs at once
/// (Add Multiple Aliases / Tags / Triggers).
struct MultiPairInputDialog: View {
let type: MultiAddItemType
Expand Down
32 changes: 19 additions & 13 deletions examples/demo/App/Views/Components/OSDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ struct OSTextField: View {
struct OSTextEditor: View {
let placeholder: String
@Binding var text: String
var minHeight: CGFloat = 90
var height: CGFloat = 90
var accessibilityID: String

@FocusState private var focused: Bool
Expand All @@ -180,7 +180,7 @@ struct OSTextEditor: View {
.padding(.horizontal, 8)
.padding(.vertical, 8)
.focused($focused)
.frame(minHeight: minHeight)
.frame(height: height)
.accessibilityIdentifier(accessibilityID)
}
.background(
Expand All @@ -193,12 +193,12 @@ struct OSTextEditor: View {
}
}

// MARK: - Centered dialog presentation
// MARK: - Dialog presentation

extension View {
/// Presents `content` as a centered modal dialog over the entire screen,
/// matching the styles.md "Dialogs" spec: 54% black backdrop, 16pt
/// horizontal / 24pt vertical insets, 28pt corner radius, white card.
/// Presents `content` as a modal dialog near the top of the screen,
Comment thread
fadi-george marked this conversation as resolved.
Resolved
/// with a 54% black backdrop, 16pt horizontal / 24pt vertical insets,
/// 28pt corner radius and a white card.
/// Tapping the backdrop dismisses.
///
/// Uses `.fullScreenCover` rather than `.overlay` so the backdrop and
Expand All @@ -208,15 +208,15 @@ extension View {
/// clear via `ClearBackgroundView` so the dialog's own backdrop is what
/// the user sees (iOS 16.4+ has `presentationBackground(.clear)`; this
/// works on the demo's 16.0 deployment target).
func osCenteredDialog<DialogContent: View>(
func osDialog<DialogContent: View>(
isPresented: Binding<Bool>,
@ViewBuilder content: @escaping () -> DialogContent
) -> some View {
modifier(OSCenteredDialogModifier(isPresented: isPresented, dialog: content))
modifier(OSDialogModifier(isPresented: isPresented, dialog: content))
}
}

private struct OSCenteredDialogModifier<DialogContent: View>: ViewModifier {
private struct OSDialogModifier<DialogContent: View>: ViewModifier {
@Binding var isPresented: Bool
@ViewBuilder var dialog: () -> DialogContent

Expand All @@ -228,10 +228,16 @@ private struct OSCenteredDialogModifier<DialogContent: View>: ViewModifier {
.contentShape(Rectangle())
.onTapGesture { isPresented = false }

dialog()
.clipShape(RoundedRectangle(cornerRadius: OS.Radius.modal))
.padding(.horizontal, 16)
.padding(.vertical, 24)
// Top-anchored and keyboard-insensitive: a dialog that moves while
// open desyncs XCUITest frame reporting from the rendered layout.
VStack(spacing: 0) {
dialog()
.clipShape(RoundedRectangle(cornerRadius: OS.Radius.modal))
.padding(.horizontal, 16)
.padding(.vertical, 24)
Spacer(minLength: 0)
}
.ignoresSafeArea(.keyboard)
}
.background(ClearBackgroundView())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/App/Views/Components/OutcomeDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import SwiftUI

/// Centered dialog for sending an outcome (normal, unique, or with value).
/// Dialog for sending an outcome (normal, unique, or with value).
struct OutcomeDialog: View {
let onSend: (String, OutcomeMode, Double?) -> Void
let onCancel: () -> Void
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/App/Views/Components/RemoveMultiDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import SwiftUI

/// Centered dialog that lets the user pick multiple keys to remove
/// Dialog that lets the user pick multiple keys to remove
/// (Remove Tags / Remove Triggers).
struct RemoveMultiDialog: View {
let type: RemoveMultiItemType
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/App/Views/Components/TooltipDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import SwiftUI

/// Tooltip dialog body shown when the user taps a section's info icon.
/// Single OK action — no Cancel. Presented as a centered modal via
/// `osCenteredDialog`, so this view renders only the card chrome.
/// Single OK action — no Cancel. Presented as a modal via
/// `osDialog`, so this view renders only the card chrome.
struct TooltipDialog: View {
let tooltip: TooltipData
let onClose: () -> Void
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/App/Views/Components/TrackEventDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import SwiftUI

/// Centered dialog that captures an event name plus an optional
/// Dialog that captures an event name plus an optional
/// JSON properties payload.
struct TrackEventDialog: View {
let onTrack: (String, [String: Any]?) -> Void
Expand Down Expand Up @@ -61,7 +61,7 @@ struct TrackEventDialog: View {
OSTextEditor(
placeholder: "{ \"key\": \"value\" }",
text: $propertiesText,
minHeight: 120,
height: 120,
accessibilityID: "event_properties_input"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/demo/App/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct ContentView: View {
SecondaryView()
}
}
.osCenteredDialog(
.osDialog(
isPresented: Binding(
get: { viewModel.activeTooltip != nil },
set: { isPresented in if !isPresented { viewModel.dismissTooltip() } }
Expand Down
Loading
Loading