-
Notifications
You must be signed in to change notification settings - Fork 61
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 #601 from aashay-gaikwad/ios-samples
iOS support and target apps
- Loading branch information
Showing
66 changed files
with
2,352 additions
and
7 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
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
appyx-interactions/common/src/iosMain/kotlin/com/bumble/appyx/interactions/SystemClock.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,8 @@ | ||
package com.bumble.appyx.interactions | ||
|
||
import platform.CoreFoundation.CFAbsoluteTimeGetCurrent | ||
|
||
actual object SystemClock { | ||
|
||
actual fun nanoTime(): Long = CFAbsoluteTimeGetCurrent().toLong() | ||
} |
9 changes: 9 additions & 0 deletions
9
appyx-interactions/common/src/iosMain/kotlin/com/bumble/appyx/interactions/UUID.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,9 @@ | ||
package com.bumble.appyx.interactions | ||
|
||
import platform.Foundation.NSUUID | ||
|
||
actual object UUID { | ||
|
||
actual fun randomUUID(): String = NSUUID().UUIDString() | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
appyx-interactions/common/src/iosMain/kotlin/com/bumble/appyx/interactions/platform.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,5 @@ | ||
package com.bumble.appyx.interactions | ||
|
||
actual fun getPlatformName(): String { | ||
return "iOS" | ||
} |
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
77 changes: 77 additions & 0 deletions
77
...vigation/common/src/iosMain/kotlin/com/bumble/appyx/navigation/integration/IosNodeHost.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,77 @@ | ||
package com.bumble.appyx.navigation.integration | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.bumble.appyx.navigation.integrationpoint.IntegrationPoint | ||
import com.bumble.appyx.navigation.node.Node | ||
import com.bumble.appyx.navigation.platform.LocalOnBackPressedDispatcherOwner | ||
import com.bumble.appyx.navigation.platform.OnBackPressedDispatcher | ||
import com.bumble.appyx.navigation.platform.OnBackPressedDispatcherOwner | ||
import com.bumble.appyx.navigation.platform.PlatformLifecycleRegistry | ||
import com.bumble.appyx.utils.customisations.NodeCustomisationDirectory | ||
import com.bumble.appyx.utils.customisations.NodeCustomisationDirectoryImpl | ||
import kotlinx.cinterop.useContents | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.launch | ||
import platform.UIKit.UIScreen | ||
|
||
@Suppress("ComposableParamOrder") // detekt complains as 'factory' param isn't a pure lambda | ||
@Composable | ||
fun <N : Node> IosNodeHost( | ||
onBackPressedEvents: Flow<Unit>, | ||
modifier: Modifier = Modifier, | ||
integrationPoint: IntegrationPoint, | ||
customisations: NodeCustomisationDirectory = remember { NodeCustomisationDirectoryImpl() }, | ||
factory: NodeFactory<N>, | ||
) { | ||
val platformLifecycleRegistry = remember { | ||
PlatformLifecycleRegistry() | ||
} | ||
val mainScreen = UIScreen.mainScreen | ||
val screenBounds = mainScreen.bounds | ||
|
||
// Calculate the width and height in dp | ||
val dpWidth = screenBounds.useContents { size.width }.pixelsToDp() | ||
val dpHeight = screenBounds.useContents { size.height }.pixelsToDp() | ||
|
||
val onBackPressedDispatcherOwner = remember { | ||
object : OnBackPressedDispatcherOwner { | ||
override val onBackPressedDispatcher: OnBackPressedDispatcher = | ||
OnBackPressedDispatcher { integrationPoint.handleUpNavigation() } | ||
} | ||
} | ||
|
||
val scope = rememberCoroutineScope() | ||
LaunchedEffect(onBackPressedEvents) { | ||
scope.launch { | ||
onBackPressedEvents.collect { | ||
onBackPressedDispatcherOwner.onBackPressedDispatcher.onBackPressed() | ||
} | ||
} | ||
} | ||
|
||
CompositionLocalProvider(LocalOnBackPressedDispatcherOwner provides onBackPressedDispatcherOwner) { | ||
NodeHost( | ||
lifecycle = platformLifecycleRegistry, | ||
integrationPoint = integrationPoint, | ||
modifier = modifier, | ||
customisations = customisations, | ||
screenSize = ScreenSize( | ||
widthDp = dpWidth.dp, | ||
heightDp = dpHeight.dp, | ||
), | ||
factory = factory, | ||
) | ||
} | ||
} | ||
|
||
private fun Double.pixelsToDp(): Double { | ||
val mainScreen = UIScreen.mainScreen | ||
val scale = mainScreen.scale | ||
return this / scale | ||
} |
24 changes: 24 additions & 0 deletions
24
...common/src/iosMain/kotlin/com/bumble/appyx/navigation/integration/MainIntegrationPoint.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,24 @@ | ||
package com.bumble.appyx.navigation.integration | ||
|
||
import com.bumble.appyx.navigation.integrationpoint.IntegrationPoint | ||
import platform.UIKit.UIViewController | ||
import platform.UIKit.navigationController | ||
|
||
class MainIntegrationPoint: IntegrationPoint() { | ||
private lateinit var viewController: UIViewController | ||
|
||
override val isChangingConfigurations: Boolean | ||
get() = false | ||
|
||
fun setViewController(viewController: UIViewController) { | ||
this.viewController = viewController | ||
} | ||
|
||
override fun onRootFinished() { | ||
viewController.dismissModalViewControllerAnimated(false) | ||
} | ||
|
||
override fun handleUpNavigation() { | ||
viewController.navigationController?.popViewControllerAnimated(false) | ||
} | ||
} |
Oops, something went wrong.