Skip to content

Commit

Permalink
Merge pull request #601 from aashay-gaikwad/ios-samples
Browse files Browse the repository at this point in the history
iOS support and target apps
  • Loading branch information
zsoltk authored Oct 2, 2023
2 parents aed7612 + 7ee043b commit 542e5de
Show file tree
Hide file tree
Showing 66 changed files with 2,352 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ build/
local.properties
site/
__pycache__
iosApp/Podfile.lock
**/iosApp/Pods/*
**/iosApp/iosApp.xcworkspace/*
**/iosApp/iosApp.xcodeproj/*
!**/iosApp/iosApp.xcodeproj/project.pbxproj
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
### Added

- [#579](https://github.com/bumble-tech/appyx/pull/579) – Expose `AndroidLifecycle` in `PlatformLifecycleRegistry` for Android
- [#601](https://github.com/bumble-tech/appyx/pull/601) – iOS support and target apps

### Fixed

Expand Down
15 changes: 15 additions & 0 deletions appyx-components/experimental/cards/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ kotlin {
moduleName = "appyx-components-experimental-cards-commons"
browser()
}
iosX64()
iosArm64()
iosSimulatorArm64()
sourceSets {
val commonMain by getting {
dependencies {
Expand All @@ -41,6 +44,15 @@ kotlin {
}
val androidMain by getting
val desktopMain by getting
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
}
}

Expand All @@ -49,4 +61,7 @@ dependencies {
add("kspAndroid", project(":ksp:mutable-ui-processor"))
add("kspDesktop", project(":ksp:mutable-ui-processor"))
add("kspJs", project(":ksp:mutable-ui-processor"))
add("kspIosArm64", project(":ksp:mutable-ui-processor"))
add("kspIosX64", project(":ksp:mutable-ui-processor"))
add("kspIosSimulatorArm64", project(":ksp:mutable-ui-processor"))
}
15 changes: 15 additions & 0 deletions appyx-components/experimental/modal/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ kotlin {
moduleName = "appyx-components-modal-commons"
browser()
}
iosX64()
iosArm64()
iosSimulatorArm64()
sourceSets {
val commonMain by getting {
dependencies {
Expand All @@ -46,6 +49,15 @@ kotlin {
}
}
val desktopMain by getting
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
}
}

Expand All @@ -54,4 +66,7 @@ dependencies {
add("kspAndroid", project(":ksp:mutable-ui-processor"))
add("kspDesktop", project(":ksp:mutable-ui-processor"))
add("kspJs", project(":ksp:mutable-ui-processor"))
add("kspIosArm64", project(":ksp:mutable-ui-processor"))
add("kspIosX64", project(":ksp:mutable-ui-processor"))
add("kspIosSimulatorArm64", project(":ksp:mutable-ui-processor"))
}
15 changes: 15 additions & 0 deletions appyx-components/experimental/promoter/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ kotlin {
moduleName = "appyx-components-experimental-promoter-commons"
browser()
}
iosX64()
iosArm64()
iosSimulatorArm64()
sourceSets {
val commonMain by getting {
dependencies {
Expand All @@ -42,6 +45,15 @@ kotlin {
}
val androidMain by getting
val desktopMain by getting
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
}
}

Expand All @@ -50,4 +62,7 @@ dependencies {
add("kspAndroid", project(":ksp:mutable-ui-processor"))
add("kspDesktop", project(":ksp:mutable-ui-processor"))
add("kspJs", project(":ksp:mutable-ui-processor"))
add("kspIosArm64", project(":ksp:mutable-ui-processor"))
add("kspIosX64", project(":ksp:mutable-ui-processor"))
add("kspIosSimulatorArm64", project(":ksp:mutable-ui-processor"))
}
18 changes: 18 additions & 0 deletions appyx-components/stable/backstack/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ kotlin {
moduleName = "appyx-components-stable-backstack-commons"
browser()
}

iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
val commonMain by getting {
dependencies {
Expand All @@ -42,6 +47,16 @@ kotlin {
val androidMain by getting
val desktopMain by getting
val jsMain by getting

val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
}
}

Expand All @@ -50,4 +65,7 @@ dependencies {
add("kspAndroid", project(":ksp:mutable-ui-processor"))
add("kspDesktop", project(":ksp:mutable-ui-processor"))
add("kspJs", project(":ksp:mutable-ui-processor"))
add("kspIosArm64", project(":ksp:mutable-ui-processor"))
add("kspIosX64", project(":ksp:mutable-ui-processor"))
add("kspIosSimulatorArm64", project(":ksp:mutable-ui-processor"))
}
18 changes: 18 additions & 0 deletions appyx-components/stable/spotlight/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ kotlin {
moduleName = "appyx-components-stable-spotlight-commons"
browser()
}

iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
val commonMain by getting {
dependencies {
Expand All @@ -45,6 +50,16 @@ kotlin {
}
}
val desktopMain by getting

val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
}
}

Expand All @@ -53,4 +68,7 @@ dependencies {
add("kspAndroid", project(":ksp:mutable-ui-processor"))
add("kspDesktop", project(":ksp:mutable-ui-processor"))
add("kspJs", project(":ksp:mutable-ui-processor"))
add("kspIosArm64", project(":ksp:mutable-ui-processor"))
add("kspIosX64", project(":ksp:mutable-ui-processor"))
add("kspIosSimulatorArm64", project(":ksp:mutable-ui-processor"))
}
15 changes: 15 additions & 0 deletions appyx-interactions/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ kotlin {
moduleName = "appyx-interactions-common"
browser()
}

iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
val commonMain by getting {
dependencies {
Expand Down Expand Up @@ -62,5 +67,15 @@ kotlin {
implementation(npm("uuid", libs.versions.uuid.get()))
}
}

val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
}
}
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()
}
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()

}
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"
}
14 changes: 14 additions & 0 deletions appyx-navigation/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ kotlin {
moduleName = "appyx-navigation-common"
browser()
}

iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
val commonMain by getting {
dependencies {
Expand Down Expand Up @@ -62,6 +67,15 @@ kotlin {
implementation(npm("uuid", libs.versions.uuid.get()))
}
}
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import androidx.compose.runtime.Composable

@Composable
expect fun PlatformBackHandler(
enabled: Boolean = true,
enabled: Boolean,
onBack: () -> Unit
)
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
}
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)
}
}
Loading

0 comments on commit 542e5de

Please sign in to comment.