Skip to content

Commit

Permalink
Merge pull request #51 from 0x1-company/share
Browse files Browse the repository at this point in the history
feat: share
  • Loading branch information
tomokisun authored Dec 28, 2023
2 parents f286e35 + 32ac842 commit fd3b456
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions Packages/BeMatch/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ let package = Package(
"Styleguide",
"BeMatchClient",
"AnalyticsKeys",
.product(name: "ActivityView", package: "SDK"),
.product(name: "FeedbackGeneratorClient", package: "SDK"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public extension ButtonClickKeys {
var close: String { "close" }
var notNow: String { "not_now" }
var delete: String { "delete" }
var share: String { "share" }
}
3 changes: 2 additions & 1 deletion Packages/BeMatch/Sources/OnboardFeature/Onboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public struct OnboardLogic {
return .none

case .path(.element(_, .gender(.delegate(.nextScreen)))):
state.path.append(.sample())
// state.path.append(.sample())
state.path.append(.capture())
return .none

case .path(.element(_, .sample(.delegate(.nextScreen)))):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import ActivityView
import AnalyticsClient
import AnalyticsKeys
import BeMatch
import BeMatchClient
import ComposableArchitecture
Expand All @@ -10,15 +12,24 @@ import SwiftUI
public struct RecommendationEmptyLogic {
public init() {}

public struct CompletionWithItems: Equatable {
public let activityType: UIActivity.ActivityType?
public let result: Bool
}

public struct State: Equatable {
var sharedURL = Constants.appStoreForEmptyURL
@BindingState var isPresented = false
public init() {}
}

public enum Action {
public enum Action: BindableAction {
case onTask
case onAppear
case shareButtonTapped
case currentUserResponse(Result<BeMatch.CurrentUserQuery.Data, Error>)
case onCompletion(CompletionWithItems)
case binding(BindingAction<State>)
}

@Dependency(\.analytics) var analytics
Expand All @@ -29,6 +40,7 @@ public struct RecommendationEmptyLogic {
}

public var body: some Reducer<State, Action> {
BindingReducer()
Reduce<State, Action> { state, action in
switch action {
case .onTask:
Expand All @@ -45,13 +57,25 @@ public struct RecommendationEmptyLogic {
analytics.logScreen(screenName: "RecommendationEmpty", of: self)
return .none

case .shareButtonTapped:
state.isPresented = true
return .none

case let .currentUserResponse(.success(data)):
state.sharedURL = data.currentUser.gender == .female
? Constants.appStoreFemaleForEmptyURL
: Constants.appStoreForEmptyURL
return .none

case .currentUserResponse(.failure):
case let .onCompletion(completion):
state.isPresented = false
analytics.logEvent("activity_completion", [
"activity_type": completion.activityType?.rawValue,
"result": completion.result,
])
return .none

default:
return .none
}
}
Expand Down Expand Up @@ -79,7 +103,9 @@ public struct RecommendationEmptyView: View {
.foregroundStyle(Color.white)
.multilineTextAlignment(.center)

ShareLink(item: viewStore.sharedURL) {
Button {
store.send(.shareButtonTapped)
} label: {
Text("Share", bundle: .module)
.font(.system(.subheadline, weight: .semibold))
.frame(height: 50)
Expand All @@ -95,6 +121,22 @@ public struct RecommendationEmptyView: View {
.background(Color.black)
.task { await store.send(.onTask).finish() }
.onAppear { store.send(.onAppear) }
.sheet(isPresented: viewStore.$isPresented) {
ActivityView(
activityItems: [viewStore.sharedURL],
applicationActivities: nil
) { activityType, result, _, _ in
store.send(
.onCompletion(
RecommendationEmptyLogic.CompletionWithItems(
activityType: activityType,
result: result
)
)
)
}
.presentationDetents([.medium, .large])
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public struct RecommendationLogic {
? .empty()
: .swipe(RecommendationSwipeLogic.State(rows: rows))

state.child = .empty()

return .none

case let .child(.swipe(.delegate(.matched(username)))):
Expand Down
2 changes: 2 additions & 0 deletions Packages/SDK/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var package = Package(
.iOS(.v16),
],
products: [
.library(name: "ActivityView", targets: ["ActivityView"]),
.library(name: "AnalyticsClient", targets: ["AnalyticsClient"]),
.library(name: "ApolloClientHelpers", targets: ["ApolloClientHelpers"]),
.library(name: "ApolloConcurrency", targets: ["ApolloConcurrency"]),
Expand Down Expand Up @@ -48,6 +49,7 @@ var package = Package(
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "1.5.6"),
],
targets: [
.target(name: "ActivityView"),
.target(name: "AnalyticsClient", dependencies: [
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "FirebaseAnalytics", package: "firebase-ios-sdk"),
Expand Down

0 comments on commit fd3b456

Please sign in to comment.