-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c821c8
commit 75caba1
Showing
14 changed files
with
308 additions
and
1 deletion.
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
8 changes: 8 additions & 0 deletions
8
...AnalyticsServiceInterface/Events/Announcements/Analytics+ChristmasAnnouncementShown.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,8 @@ | ||
extension Analytics.Announcement { | ||
public struct ChristmasAnnouncementShown: TrackableEvent { | ||
public let name = "Announcement.ChristmasAnnouncementShown" | ||
public let payload: [String: String]? = nil | ||
|
||
public init() {} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
ios/Approach/Sources/AnnouncementsFeature/Announcements.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,97 @@ | ||
import AssetsLibrary | ||
import ComposableArchitecture | ||
import FeatureActionLibrary | ||
import PreferenceServiceInterface | ||
import SwiftUI | ||
import SwiftUIExtensionsLibrary | ||
|
||
@Reducer | ||
public struct Announcements: Reducer { | ||
public struct State: Equatable { | ||
@PresentationState public var christmas: Christmas2023Announcement.State? | ||
|
||
public init() {} | ||
} | ||
|
||
public enum Action: FeatureAction, Equatable { | ||
public enum ViewAction: Equatable { | ||
case onFirstAppear | ||
case didFinishDismissingAnnouncement | ||
} | ||
|
||
public enum InternalAction: Equatable { | ||
case showChristmasAnnouncement | ||
case christmas(PresentationAction<Christmas2023Announcement.Action>) | ||
} | ||
|
||
public enum DelegateAction: Equatable {} | ||
|
||
case view(ViewAction) | ||
case delegate(DelegateAction) | ||
case `internal`(InternalAction) | ||
} | ||
|
||
public init() {} | ||
|
||
@Dependency(\.preferences) var preferences | ||
|
||
public var body: some ReducerOf<Self> { | ||
Reduce<State, Action> { state, action in | ||
switch action { | ||
case let .view(viewAction): | ||
switch viewAction { | ||
case .onFirstAppear: | ||
return .run { send in | ||
if Christmas2023Announcement.meetsExpectationsToShow() { | ||
await send(.internal(.showChristmasAnnouncement)) | ||
} | ||
} | ||
|
||
case .didFinishDismissingAnnouncement: | ||
return .run { _ in preferences.setKey(.announcementChristmasBanner2023Hidden, toBool: true) } | ||
} | ||
|
||
case let .internal(internalAction): | ||
switch internalAction { | ||
case .showChristmasAnnouncement: | ||
state.christmas = .init() | ||
return .none | ||
|
||
case let .christmas(.presented(.delegate(delegateAction))): | ||
switch delegateAction { | ||
case .openAppIconSettings: | ||
return .none | ||
} | ||
|
||
case .christmas(.presented(.view)), .christmas(.presented(.internal)), .christmas(.dismiss): | ||
return .none | ||
} | ||
|
||
case .delegate: | ||
return .none | ||
} | ||
} | ||
.ifLet(\.$christmas, action: /Action.internal..Action.InternalAction.christmas) { | ||
Christmas2023Announcement() | ||
} | ||
} | ||
} | ||
|
||
// MARK: - View | ||
|
||
extension View { | ||
public func announcements( | ||
store: Store<Announcements.State, Announcements.Action> | ||
) -> some View { | ||
self | ||
.onFirstAppear { store.send(.view(.onFirstAppear)) } | ||
.sheet( | ||
store: store.scope(state: \.$christmas, action: { .internal(.christmas($0)) }), | ||
onDismiss: { store.send(.view(.didFinishDismissingAnnouncement)) }, | ||
content: { store in | ||
Christmas2023AnnouncementView(store: store) | ||
.presentationDetents([.medium]) | ||
} | ||
) | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
ios/Approach/Sources/AnnouncementsFeature/Christmas2023Announcement.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,124 @@ | ||
import AnalyticsServiceInterface | ||
import AssetsLibrary | ||
import ComposableArchitecture | ||
import FeatureActionLibrary | ||
import PreferenceServiceInterface | ||
import StringsLibrary | ||
import SwiftUI | ||
import ViewsLibrary | ||
|
||
public struct Christmas2023Announcement: Reducer { | ||
static func meetsExpectationsToShow() -> Bool { | ||
@Dependency(\.preferences) var preferences | ||
let christmas2023AnnouncementHiddden = preferences.bool(forKey: .announcementChristmasBanner2023Hidden) ?? false | ||
guard !christmas2023AnnouncementHiddden else { return false } | ||
|
||
@Dependency(\.date) var date | ||
// Before January 1, 2024 | ||
return date() < Date(timeIntervalSince1970: 1704067200) | ||
} | ||
|
||
public struct State: Equatable {} | ||
public enum Action: FeatureAction, Equatable { | ||
public enum ViewAction: Equatable { | ||
case onFirstAppear | ||
case didTapOpenAppSettings | ||
case didTapDismiss | ||
} | ||
public enum DelegateAction: Equatable { | ||
case openAppIconSettings | ||
} | ||
public enum InternalAction: Equatable {} | ||
|
||
case view(ViewAction) | ||
case delegate(DelegateAction) | ||
case `internal`(InternalAction) | ||
} | ||
|
||
@Dependency(\.dismiss) var dismiss | ||
|
||
init() {} | ||
|
||
public var body: some ReducerOf<Self> { | ||
Reduce<State, Action> { state, action in | ||
switch action { | ||
case let .view(viewAction): | ||
switch viewAction { | ||
case .onFirstAppear: | ||
return .none | ||
|
||
case .didTapOpenAppSettings: | ||
return .concatenate( | ||
.send(.delegate(.openAppIconSettings)), | ||
.run { _ in await dismiss() } | ||
) | ||
|
||
case .didTapDismiss: | ||
return .run { _ in await dismiss() } | ||
} | ||
|
||
case let .internal(internalAction): | ||
switch internalAction { | ||
case .never: | ||
return .none | ||
} | ||
|
||
case .delegate: | ||
return .none | ||
} | ||
} | ||
|
||
AnalyticsReducer<State, Action> { _, action in | ||
switch action { | ||
case .view(.onFirstAppear): | ||
return Analytics.Announcement.ChristmasAnnouncementShown() | ||
default: | ||
return nil | ||
} | ||
} | ||
} | ||
} | ||
|
||
public struct Christmas2023AnnouncementView: View { | ||
let store: StoreOf<Christmas2023Announcement> | ||
|
||
public var body: some View { | ||
VStack(spacing: 0) { | ||
Spacer() | ||
|
||
Text(Strings.Announcement.Christmas2023.title) | ||
.font(.headline) | ||
.multilineTextAlignment(.center) | ||
|
||
Image(uiImage: UIImage(named: AppIcon.christmas.rawValue) ?? UIImage()) | ||
.resizable() | ||
.scaledToFit() | ||
.frame(width: .extraLargeIcon) | ||
.cornerRadius(.standardRadius) | ||
.shadow(radius: .standardRadius) | ||
.padding(.horizontal, .smallSpacing) | ||
.padding(.vertical, .standardSpacing) | ||
|
||
Text(Strings.Announcement.Christmas2023.message) | ||
.font(.body) | ||
.multilineTextAlignment(.center) | ||
|
||
Spacer() | ||
|
||
Button { store.send(.view(.didTapOpenAppSettings)) } label: { | ||
Text(Strings.Announcement.Christmas2023.openSettings) | ||
.frame(maxWidth: .infinity) | ||
} | ||
.modifier(PrimaryButton()) | ||
.padding(.bottom, .smallSpacing) | ||
|
||
Button { store.send(.view(.didTapDismiss)) } label: { | ||
Text(Strings.Action.dismiss) | ||
.frame(maxWidth: .infinity) | ||
.padding(.vertical, .smallSpacing) | ||
} | ||
} | ||
.onFirstAppear { store.send(.view(.onFirstAppear)) } | ||
.padding() | ||
} | ||
} |
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
Oops, something went wrong.