-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from thomaskioko/feature/decompose-ios
[iOS] Migrate to Decompose
- Loading branch information
Showing
140 changed files
with
1,960 additions
and
1,650 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
12 changes: 6 additions & 6 deletions
12
...c/commonMain/kotlin/com/thomaskioko/tvmaniac/datastore/testing/FakeDatastoreRepository.kt
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
14 changes: 14 additions & 0 deletions
14
...ain/kotlin/com/thomaskioko/tvmaniac/traktauth/implementation/TraktAuthManagerComponent.kt
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,14 @@ | ||
package com.thomaskioko.tvmaniac.traktauth.implementation | ||
|
||
import com.thomaskioko.tvmaniac.traktauth.api.TraktAuthManager | ||
import com.thomaskioko.tvmaniac.util.scope.ActivityScope | ||
import me.tatarka.inject.annotations.Provides | ||
|
||
interface TraktAuthManagerComponent { | ||
|
||
@ActivityScope | ||
@Provides | ||
fun provideTraktAuthManager( | ||
bind: TraktAuthManagerImpl, | ||
): TraktAuthManager = bind | ||
} |
7 changes: 7 additions & 0 deletions
7
...mmonMain/kotlin/com/thomaskioko/tvmaniac/traktauth/implementation/TraktAuthManagerImpl.kt
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,7 @@ | ||
package com.thomaskioko.tvmaniac.traktauth.implementation | ||
|
||
import com.thomaskioko.tvmaniac.traktauth.api.TraktAuthManager | ||
import me.tatarka.inject.annotations.Inject | ||
|
||
@Inject | ||
expect class TraktAuthManagerImpl : TraktAuthManager |
17 changes: 17 additions & 0 deletions
17
.../iosMain/kotlin/com/thomaskioko/tvmaniac/traktauth/implementation/TraktAuthManagerImpl.kt
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,17 @@ | ||
package com.thomaskioko.tvmaniac.traktauth.implementation | ||
|
||
import com.thomaskioko.tvmaniac.traktauth.api.TraktAuthManager | ||
import me.tatarka.inject.annotations.Inject | ||
|
||
// TODO:: Replace with actual typealias. See https://youtrack.jetbrains.com/issue/KT-61573 | ||
@Inject | ||
actual class TraktAuthManagerImpl : TraktAuthManager { | ||
|
||
override fun launchWebView() { | ||
// NO OP | ||
} | ||
|
||
override fun registerResult() { | ||
// NO OP | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
.../jvmMain/kotlin/com/thomaskioko/tvmaniac/traktauth/implementation/TraktAuthManagerImpl.kt
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,15 @@ | ||
package com.thomaskioko.tvmaniac.traktauth.implementation | ||
|
||
import com.thomaskioko.tvmaniac.traktauth.api.TraktAuthManager | ||
import me.tatarka.inject.annotations.Inject | ||
|
||
@Inject | ||
actual class TraktAuthManagerImpl : TraktAuthManager { | ||
override fun launchWebView() { | ||
// NO OP | ||
} | ||
|
||
override fun registerResult() { | ||
// NO OP | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
core/util/src/commonMain/kotlin/com/thomaskioko/tvmaniac/util/decompose/DecomposeUtils.kt
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,65 @@ | ||
package com.thomaskioko.tvmaniac.util.decompose | ||
|
||
import com.arkivanov.decompose.value.MutableValue | ||
import com.arkivanov.decompose.value.Value | ||
import com.arkivanov.essenty.lifecycle.Lifecycle | ||
import com.arkivanov.essenty.lifecycle.LifecycleOwner | ||
import com.arkivanov.essenty.lifecycle.doOnDestroy | ||
import com.arkivanov.essenty.lifecycle.subscribe | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.SupervisorJob | ||
import kotlinx.coroutines.cancel | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
/** | ||
* This helper implementation in from Cofetti Kmp App | ||
* See https://github.com/joreilly/Confetti/blob/fb832c2131b2f3e5276a1a3a30666aa571e1e17e/shared/src/commonMain/kotlin/dev/johnoreilly/confetti/decompose/DecomposeUtils.kt#L27 | ||
*/ | ||
|
||
fun LifecycleOwner.coroutineScope( | ||
context: CoroutineContext = Dispatchers.Main.immediate, | ||
): CoroutineScope { | ||
val scope = CoroutineScope(context + SupervisorJob()) | ||
lifecycle.doOnDestroy(scope::cancel) | ||
|
||
return scope | ||
} | ||
|
||
fun <T : Any> StateFlow<T>.asValue( | ||
lifecycle: Lifecycle, | ||
context: CoroutineContext = Dispatchers.Main.immediate, | ||
): Value<T> = | ||
asValue( | ||
initialValue = value, | ||
lifecycle = lifecycle, | ||
context = context, | ||
) | ||
|
||
fun <T : Any> Flow<T>.asValue( | ||
initialValue: T, | ||
lifecycle: Lifecycle, | ||
context: CoroutineContext = Dispatchers.Main.immediate, | ||
): Value<T> { | ||
val value = MutableValue(initialValue) | ||
var scope: CoroutineScope? = null | ||
|
||
lifecycle.subscribe( | ||
onStart = { | ||
scope = CoroutineScope(context).apply { | ||
launch { | ||
collect { value.value = it } | ||
} | ||
} | ||
}, | ||
onStop = { | ||
scope?.cancel() | ||
scope = null | ||
}, | ||
) | ||
|
||
return value | ||
} |
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.