Skip to content

Commit

Permalink
apply & add required package
Browse files Browse the repository at this point in the history
  • Loading branch information
ry-itto committed Aug 22, 2023
1 parent c275399 commit ebdde19
Show file tree
Hide file tree
Showing 18 changed files with 355 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.github.droidkaigi.confsched2023.shared

import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.ObjCProtocol
import kotlinx.cinterop.getOriginalKotlinClass

@OptIn(BetaInteropApi::class)
fun KmpEntryPoint.get(objCProtocol: ObjCProtocol): Any {
val kClazz = getOriginalKotlinClass(objCProtocol)!!
return get(kClazz)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
D77DAF8329FAA14A007195DB /* DroidKaigi2023Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77DAF8229FAA14A007195DB /* DroidKaigi2023Tests.swift */; };
D77DAF8D29FAA14A007195DB /* DroidKaigi2023UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77DAF8C29FAA14A007195DB /* DroidKaigi2023UITests.swift */; };
D77DAF8F29FAA14A007195DB /* DroidKaigi2023UITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77DAF8E29FAA14A007195DB /* DroidKaigi2023UITestsLaunchTests.swift */; };
E823229C2A93E4BA005C0DBD /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = E823229B2A93E4BA005C0DBD /* GoogleService-Info.plist */; };
E8BCCCE72A8011E8004010F7 /* Modules in Resources */ = {isa = PBXBuildFile; fileRef = E8BCCCE62A8011E8004010F7 /* Modules */; };
E8BCCCEC2A80123E004010F7 /* Navigation in Frameworks */ = {isa = PBXBuildFile; productRef = E8BCCCEB2A80123E004010F7 /* Navigation */; };
E8BCCCF12A80126D004010F7 /* ci_post_clone.sh in Resources */ = {isa = PBXBuildFile; fileRef = E8BCCCEF2A80126D004010F7 /* ci_post_clone.sh */; };
Expand Down Expand Up @@ -46,6 +47,7 @@
D77DAF8829FAA14A007195DB /* DroidKaigi2023UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DroidKaigi2023UITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D77DAF8C29FAA14A007195DB /* DroidKaigi2023UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DroidKaigi2023UITests.swift; sourceTree = "<group>"; };
D77DAF8E29FAA14A007195DB /* DroidKaigi2023UITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DroidKaigi2023UITestsLaunchTests.swift; sourceTree = "<group>"; };
E823229B2A93E4BA005C0DBD /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
E8BCCCE62A8011E8004010F7 /* Modules */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Modules; path = ../../Modules; sourceTree = "<group>"; };
E8BCCCEF2A80126D004010F7 /* ci_post_clone.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = ci_post_clone.sh; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -112,6 +114,7 @@
D77DAF7029FAA148007195DB /* App.swift */,
D77DAF7429FAA149007195DB /* Assets.xcassets */,
D77DAF7629FAA149007195DB /* DroidKaigi2023.entitlements */,
E823229B2A93E4BA005C0DBD /* GoogleService-Info.plist */,
D77DAF7729FAA149007195DB /* Preview Content */,
);
path = DroidKaigi2023;
Expand Down Expand Up @@ -261,6 +264,7 @@
files = (
E8BCCCE72A8011E8004010F7 /* Modules in Resources */,
D77DAF7929FAA149007195DB /* Preview Assets.xcassets in Resources */,
E823229C2A93E4BA005C0DBD /* GoogleService-Info.plist in Resources */,
D77DAF7529FAA149007195DB /* Assets.xcassets in Resources */,
E8BCCCF12A80126D004010F7 /* ci_post_clone.sh in Resources */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"pins" : [
{
"identity" : "abseil-cpp-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/abseil-cpp-binary.git",
"state" : {
"revision" : "bfc0b6f81adc06ce5121eb23f628473638d67c5c",
"version" : "1.2022062300.0"
}
},
{
"identity" : "collectionconcurrencykit",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -27,6 +36,87 @@
"version" : "1.7.2"
}
},
{
"identity" : "firebase-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk",
"state" : {
"revision" : "df2171b0c6afb9e9d4f7e07669d558c510b9f6be",
"version" : "10.13.0"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "03b9beee1a61f62d32c521e172e192a1663a5e8b",
"version" : "10.13.0"
}
},
{
"identity" : "googledatatransport",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleDataTransport.git",
"state" : {
"revision" : "aae45a320fd0d11811820335b1eabc8753902a40",
"version" : "9.2.5"
}
},
{
"identity" : "googleutilities",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleUtilities.git",
"state" : {
"revision" : "c38ce365d77b04a9a300c31061c5227589e5597b",
"version" : "7.11.5"
}
},
{
"identity" : "grpc-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/grpc-binary.git",
"state" : {
"revision" : "f1b366129d1125be7db83247e003fc333104b569",
"version" : "1.50.2"
}
},
{
"identity" : "gtm-session-fetcher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "d415594121c9e8a4f9d79cecee0965cf35e74dbd",
"version" : "3.1.1"
}
},
{
"identity" : "leveldb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/leveldb.git",
"state" : {
"revision" : "0706abcc6b0bd9cedfbb015ba840e4a780b5159b",
"version" : "1.22.2"
}
},
{
"identity" : "nanopb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/nanopb.git",
"state" : {
"revision" : "819d0a2173aff699fb8c364b6fb906f7cdb1a692",
"version" : "2.30909.0"
}
},
{
"identity" : "promises",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/promises.git",
"state" : {
"revision" : "e70e889c0196c76d22759eb50d6a0270ca9f1d9e",
"version" : "2.3.1"
}
},
{
"identity" : "sourcekitten",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -108,6 +198,15 @@
"version" : "1.0.2"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "ce20dc083ee485524b802669890291c0d8090170",
"version" : "1.22.1"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
Expand Down
36 changes: 36 additions & 0 deletions app-ios/App/DroidKaigi2023/DroidKaigi2023/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>1046519477136-gni68m3pq6059ivee422f6mfpp7h1c0h.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.1046519477136-gni68m3pq6059ivee422f6mfpp7h1c0h</string>
<key>ANDROID_CLIENT_ID</key>
<string>1046519477136-8nv86645bl6a09hr0rqrr7qso3u9n16u.apps.googleusercontent.com</string>
<key>API_KEY</key>
<string>AIzaSyDl9v9XzP31jrauM1twqkNPi-m5J3B2nrM</string>
<key>GCM_SENDER_ID</key>
<string>1046519477136</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>io.github.droidkaigi.DroidKaigi2023</string>
<key>PROJECT_ID</key>
<string>ssot-api-staging</string>
<key>STORAGE_BUCKET</key>
<string>ssot-api-staging.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false/>
<key>IS_ANALYTICS_ENABLED</key>
<false/>
<key>IS_APPINVITE_ENABLED</key>
<true/>
<key>IS_GCM_ENABLED</key>
<true/>
<key>IS_SIGNIN_ENABLED</key>
<true/>
<key>GOOGLE_APP_ID</key>
<string>1:1046519477136:ios:a9459b469c5a1984a8f915</string>
</dict>
</plist>
19 changes: 19 additions & 0 deletions app-ios/Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var package = Package(
.package(url: "https://github.com/realm/SwiftLint", from: "0.52.4"),
.package(url: "https://github.com/SwiftGen/SwiftGenPlugin", from: "6.6.2"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.0.0"),
.package(url: "https://github.com/firebase/firebase-ios-sdk", from: "10.13.0"),
],
targets: [
.target(
Expand Down Expand Up @@ -53,6 +54,14 @@ var package = Package(
]
),

.target(
name: "Auth",
dependencies: [
"shared",
.product(name: "FirebaseAuth", package: "firebase-ios-sdk"),
]
),

.target(
name: "Component",
dependencies: [
Expand Down Expand Up @@ -91,7 +100,9 @@ var package = Package(
.target(
name: "KMPContainer",
dependencies: [
"Auth",
"shared",
"RemoteConfig",
.product(name: "Dependencies", package: "swift-dependencies"),
]
),
Expand Down Expand Up @@ -177,6 +188,14 @@ var package = Package(
]
),

.target(
name: "RemoteConfig",
dependencies: [
"shared",
.product(name: "FirebaseRemoteConfig", package: "firebase-ios-sdk"),
]
),

.target(
name: "Model",
dependencies: [
Expand Down
18 changes: 18 additions & 0 deletions app-ios/Modules/Sources/Auth/Authenticator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import FirebaseAuth
import shared

public class AuthenticatorImpl: Authenticator {
public init() {}
public func currentUser() async throws -> shared.User? {
let currentUser = Auth.auth().currentUser
let idToken = try await currentUser?.getIDToken()

return idToken.map(User.init(idToken:))
}

public func signInAnonymously() async throws -> shared.User? {
let result = try await Auth.auth().signInAnonymously()
let idToken = try await result.user.getIDToken()
return User(idToken: idToken)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ final class ContributorViewModel: ObservableObject {
state.contributors = .loading

do {
let contributors = try await contributorsData.contributors()
state.contributors = .loaded(contributors)
try await contributorsData.refresh()
for try await contributors in contributorsData.contributors() {
state.contributors = .loaded(contributors)
}
} catch let error {
state.contributors = .failed(error)
}
Expand Down
25 changes: 25 additions & 0 deletions app-ios/Modules/Sources/KMPContainer/Container.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Auth
import Firebase
import RemoteConfig
import shared

struct Container {
static let shared: Container = .init()

private let entryPoint: KmpEntryPoint
private init() {
FirebaseApp.configure()
entryPoint = .init()
entryPoint.doInit(
remoteConfigApi: RemoteConfigApiImpl(),
authenticator: AuthenticatorImpl()
)
}

func get<TypeProtocol, ReturnType>(type: TypeProtocol) -> ReturnType where TypeProtocol: Protocol {
guard let object = entryPoint.get(objCProtocol: type) as? ReturnType else {
fatalError("Not found instance for \(type)")
}
return object
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,36 @@ import Dependencies
import shared

public struct ContributorsDataProvider {
public let contributors: () async throws -> [Contributor]
private static var contributorsRepository: ContributorsRepository {
Container.shared.get(type: ContributorsRepository.self)
}

public let refresh: () async throws -> Void
public let contributors: () -> AsyncThrowingStream<[Contributor], Error>
}

extension ContributorsDataProvider: DependencyKey {
@MainActor
public static var liveValue: ContributorsDataProvider = ContributorsDataProvider(
contributors: { @MainActor in
try await FakeContributorsApiClient().contributors()
refresh: { @MainActor in
try await contributorsRepository.refresh()
},
contributors: {
contributorsRepository.contributors().stream()
}
)

public static var testValue: ContributorsDataProvider = ContributorsDataProvider(
refresh: {},
contributors: {
.init {
Contributor.companion.fakes()
}
}
)
}

public extension DependencyValues {
public extension DependencyValues {
var contributorsData: ContributorsDataProvider {
get { self[ContributorsDataProvider.self] }
set { self[ContributorsDataProvider.self] = newValue }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import shared

class FlowCollector<T>: Kotlinx_coroutines_coreFlowCollector {
let callback: (T) -> Void

init(callback: @escaping (T) -> Void) {
self.callback = callback
}

func emit(value: Any?, completionHandler: @escaping (Error?) -> Void) {
if let value = value as? T {
callback(value)
}
completionHandler(nil)
}
}

public extension Kotlinx_coroutines_coreFlow {
// Note: Calling Kotlin suspend functions from Swift/Objective-C is currently supported only on main thread
@MainActor
func stream<T>() -> AsyncThrowingStream<T, Error> {
return AsyncThrowingStream { [weak self] continuation in
self?.collect(collector: FlowCollector<T>(callback: { value in
continuation.yield(value)
}), completionHandler: { error in
if let error = error {
continuation.finish(throwing: error)
} else {
continuation.finish()
}
})
}
}
}
Loading

0 comments on commit ebdde19

Please sign in to comment.