diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..223e061 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ + +*.iml +.gradle +.idea +.kotlin +.DS_Store +build +*/build +captures +.externalNativeBuild +.cxx +local.properties +xcuserdata/ +Pods/ +*.jks +*yarn.lock diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..ffd8cb4 --- /dev/null +++ b/README.MD @@ -0,0 +1,43 @@ +# Voyant + +Kotlin Multiplatform Library + +### Publish to MavenCentral + +1) Registering a Sonatype account as described here: + https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-going-public-4a8k +2) Add developer id, name, email and the project url to + `/convention-plugins/src/main/kotlin/convention.publication.gradle.kts` +3) Add the secrets to `local.properties`: + +``` +signing.keyId=... +signing.password=... +signing.secretKeyRingFile=... +ossrhUsername=... +ossrhPassword=... +``` + +4) Run `./gradlew :voyagerX:publishAllPublicationsToSonatypeRepository` + +### Build platform artifacts + +#### Android aar + +- Run `./gradlew :voyagerX:assembleRelease` +- Output: `/voyagerX/build/outputs/aar/voyagerX-release.aar` + +#### JVM jar + +- Run `./gradlew :voyagerX:jvmJar` +- Output: `/voyagerX/build/libs/voyagerX-jvm-1.0.jar` + +#### iOS Framework + +- Run `./gradlew :voyagerX:linkReleaseFrameworkIosArm64` +- Output: `/voyagerX/build/bin/iosArm64/releaseFramework/voyagerX.framework` + +#### Wasm binary file + +- Run `./gradlew :voyagerX:wasmJsBrowserDistribution` +- Output: `/voyagerX/build/dist/wasmJs/productionExecutable/voyagerX-wasm-js.wasm` diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..648c945 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + alias(libs.plugins.multiplatform).apply(false) + alias(libs.plugins.android.library).apply(false) + alias(libs.plugins.compose.compiler).apply(false) + alias(libs.plugins.compose).apply(false) + alias(libs.plugins.android.application).apply(false) +} diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts new file mode 100644 index 0000000..fdf67ed --- /dev/null +++ b/composeApp/build.gradle.kts @@ -0,0 +1,108 @@ +import org.jetbrains.compose.ExperimentalComposeLibrary +import com.android.build.api.dsl.ManagedVirtualDevice +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree + +plugins { + alias(libs.plugins.multiplatform) + alias(libs.plugins.compose.compiler) + alias(libs.plugins.compose) + alias(libs.plugins.android.application) +} + +kotlin { + androidTarget { + compilations.all { + compileTaskProvider { + compilerOptions { + jvmTarget.set(JvmTarget.JVM_1_8) + //https://jakewharton.com/gradle-toolchains-are-rarely-a-good-idea/#what-do-i-do + freeCompilerArgs.add("-Xjdk-release=${JavaVersion.VERSION_1_8}") + } + } + } + //https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-test.html + @OptIn(ExperimentalKotlinGradlePluginApi::class) + instrumentedTestVariant.sourceSetTree.set(KotlinSourceSetTree.test) + } + + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64() + ).forEach { + it.binaries.framework { + baseName = "ComposeApp" + isStatic = true + } + } + + sourceSets { + commonMain.dependencies { + implementation(compose.runtime) + implementation(compose.foundation) + implementation(compose.material3) + implementation(compose.material) + implementation(compose.components.resources) + implementation(compose.components.uiToolingPreview) + implementation(project(":voyagerX")) + } + + commonTest.dependencies { + implementation(kotlin("test")) + @OptIn(ExperimentalComposeLibrary::class) + implementation(compose.uiTest) + } + + androidMain.dependencies { + implementation(compose.uiTooling) + implementation(libs.androidx.activityCompose) + } + + iosMain.dependencies { + } + + } +} + +android { + namespace = "com.kashif.sample" + compileSdk = 34 + + defaultConfig { + minSdk = 26 + targetSdk = 34 + + applicationId = "com.kashif.sample.androidApp" + versionCode = 1 + versionName = "1.0.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + //https://developer.android.com/studio/test/gradle-managed-devices + @Suppress("UnstableApiUsage") + testOptions { + managedDevices.devices { + maybeCreate("pixel5").apply { + device = "Pixel 5" + apiLevel = 34 + systemImageSource = "aosp" + } + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } +} + +//https://developer.android.com/develop/ui/compose/testing#setup +dependencies { + androidTestImplementation(libs.androidx.uitest.junit4) + debugImplementation(libs.androidx.uitest.testManifest) + //temporary fix: https://youtrack.jetbrains.com/issue/CMP-5864 + androidTestImplementation("androidx.test:monitor") { + version { strictly("1.6.1") } + } +} diff --git a/composeApp/src/androidMain/AndroidManifest.xml b/composeApp/src/androidMain/AndroidManifest.xml new file mode 100644 index 0000000..9caa733 --- /dev/null +++ b/composeApp/src/androidMain/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/com/kashif/sample/App.android.kt b/composeApp/src/androidMain/kotlin/com/kashif/sample/App.android.kt new file mode 100644 index 0000000..6fd465c --- /dev/null +++ b/composeApp/src/androidMain/kotlin/com/kashif/sample/App.android.kt @@ -0,0 +1,20 @@ +package com.kashif.sample + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.Preview + +class AppActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContent { App() } + } +} + +@Preview +@Composable +fun AppPreview() { App() } diff --git a/composeApp/src/androidMain/kotlin/com/kashif/sample/theme/Theme.android.kt b/composeApp/src/androidMain/kotlin/com/kashif/sample/theme/Theme.android.kt new file mode 100644 index 0000000..4e45506 --- /dev/null +++ b/composeApp/src/androidMain/kotlin/com/kashif/sample/theme/Theme.android.kt @@ -0,0 +1,19 @@ +package com.kashif.sample.theme + +import android.app.Activity +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowInsetsControllerCompat + +@Composable +internal actual fun SystemAppearance(isDark: Boolean) { + val view = LocalView.current + LaunchedEffect(isDark) { + val window = (view.context as Activity).window + WindowInsetsControllerCompat(window, window.decorView).apply { + isAppearanceLightStatusBars = isDark + isAppearanceLightNavigationBars = isDark + } + } +} \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/com/kashif/sample/voyager/VoyagerExtension.android.kt b/composeApp/src/androidMain/kotlin/com/kashif/sample/voyager/VoyagerExtension.android.kt new file mode 100644 index 0000000..7b59eb2 --- /dev/null +++ b/composeApp/src/androidMain/kotlin/com/kashif/sample/voyager/VoyagerExtension.android.kt @@ -0,0 +1,25 @@ +package com.kashif.sample.voyager + +import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.navigator.Navigator +import cafe.adriel.voyager.navigator.bottomSheet.BottomSheetNavigator + +actual fun Navigator.popX() { + pop() +} + +actual fun Navigator.popToRootX() { + popUntilRoot() +} + +actual fun Navigator.pushX(screen: Screen) { + push(screen) +} + +actual fun BottomSheetNavigator.hideX() { + hide() +} + +actual fun BottomSheetNavigator.showX(screen: Screen) { + show(screen) +} \ No newline at end of file diff --git a/composeApp/src/commonMain/composeResources/drawable/ic_cyclone.xml b/composeApp/src/commonMain/composeResources/drawable/ic_cyclone.xml new file mode 100644 index 0000000..f1c45b5 --- /dev/null +++ b/composeApp/src/commonMain/composeResources/drawable/ic_cyclone.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/composeApp/src/commonMain/composeResources/drawable/ic_dark_mode.xml b/composeApp/src/commonMain/composeResources/drawable/ic_dark_mode.xml new file mode 100644 index 0000000..0ce2444 --- /dev/null +++ b/composeApp/src/commonMain/composeResources/drawable/ic_dark_mode.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/composeApp/src/commonMain/composeResources/drawable/ic_light_mode.xml b/composeApp/src/commonMain/composeResources/drawable/ic_light_mode.xml new file mode 100644 index 0000000..b7331d3 --- /dev/null +++ b/composeApp/src/commonMain/composeResources/drawable/ic_light_mode.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/composeApp/src/commonMain/composeResources/drawable/ic_rotate_right.xml b/composeApp/src/commonMain/composeResources/drawable/ic_rotate_right.xml new file mode 100644 index 0000000..1810671 --- /dev/null +++ b/composeApp/src/commonMain/composeResources/drawable/ic_rotate_right.xml @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/composeApp/src/commonMain/composeResources/font/IndieFlower-Regular.ttf b/composeApp/src/commonMain/composeResources/font/IndieFlower-Regular.ttf new file mode 100644 index 0000000..3774ef5 Binary files /dev/null and b/composeApp/src/commonMain/composeResources/font/IndieFlower-Regular.ttf differ diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml new file mode 100644 index 0000000..b8d73e4 --- /dev/null +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -0,0 +1,7 @@ + + Cyclone + Open github + Run + Stop + Theme + \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/kashif/sample/App.kt b/composeApp/src/commonMain/kotlin/com/kashif/sample/App.kt new file mode 100644 index 0000000..8c22544 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/kashif/sample/App.kt @@ -0,0 +1,221 @@ +package com.kashif.sample + +import androidx.compose.animation.core.* +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.* +import androidx.compose.material.ExperimentalMaterialApi +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.rotate +import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.platform.LocalUriHandler +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.unit.dp +import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.navigator.LocalNavigator +import cafe.adriel.voyager.navigator.Navigator +import cafe.adriel.voyager.navigator.bottomSheet.BottomSheetNavigator +import cafe.adriel.voyager.navigator.bottomSheet.LocalBottomSheetNavigator +import cafe.adriel.voyager.navigator.currentOrThrow +import com.kashif.sample.theme.AppTheme +import com.kashif.sample.theme.LocalThemeIsDark +import com.kashif.voyant.hideX +import com.kashif.voyant.popUntilRootX +import com.kashif.voyant.popX +import com.kashif.voyant.pushX +import com.kashif.voyant.showX +import kotlinx.coroutines.isActive +import org.jetbrains.compose.resources.Font +import org.jetbrains.compose.resources.stringResource +import org.jetbrains.compose.resources.vectorResource +import voyant.composeapp.generated.resources.IndieFlower_Regular +import voyant.composeapp.generated.resources.Res +import voyant.composeapp.generated.resources.cyclone +import voyant.composeapp.generated.resources.ic_cyclone +import voyant.composeapp.generated.resources.ic_dark_mode +import voyant.composeapp.generated.resources.ic_light_mode +import voyant.composeapp.generated.resources.ic_rotate_right +import voyant.composeapp.generated.resources.open_github +import voyant.composeapp.generated.resources.run +import voyant.composeapp.generated.resources.stop +import voyant.composeapp.generated.resources.theme + +@OptIn(ExperimentalMaterialApi::class) +@Composable +internal fun App() = AppTheme { + BottomSheetNavigator { + Navigator(ScreenA()) + } +} + +class ScreenA : Screen { + @Composable + override fun Content() { + val navigator = LocalNavigator.currentOrThrow + Column( + modifier = Modifier + .fillMaxSize() + .windowInsetsPadding(WindowInsets.safeDrawing) + .padding(16.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = stringResource(Res.string.cyclone), + fontFamily = FontFamily(Font(Res.font.IndieFlower_Regular)), + style = MaterialTheme.typography.displayLarge + ) + + var isRotating by remember { mutableStateOf(false) } + + val rotate = remember { Animatable(0f) } + val target = 360f + if (isRotating) { + LaunchedEffect(Unit) { + while (isActive) { + val remaining = (target - rotate.value) / target + rotate.animateTo( + target, + animationSpec = tween( + (1_000 * remaining).toInt(), + easing = LinearEasing + ) + ) + rotate.snapTo(0f) + } + } + } + + Image( + modifier = Modifier + .size(250.dp) + .padding(16.dp) + .run { rotate(rotate.value) }, + imageVector = vectorResource(Res.drawable.ic_cyclone), + colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface), + contentDescription = null + ) + + ElevatedButton( + modifier = Modifier + .padding(horizontal = 8.dp, vertical = 4.dp) + .widthIn(min = 200.dp), + onClick = { isRotating = !isRotating }, + content = { + Icon(vectorResource(Res.drawable.ic_rotate_right), contentDescription = null) + Spacer(Modifier.size(ButtonDefaults.IconSpacing)) + Text( + stringResource(if (isRotating) Res.string.stop else Res.string.run) + ) + } + ) + + var isDark by LocalThemeIsDark.current + val icon = remember(isDark) { + if (isDark) Res.drawable.ic_light_mode + else Res.drawable.ic_dark_mode + } + + ElevatedButton( + modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp) + .widthIn(min = 200.dp), + onClick = { isDark = !isDark }, + content = { + Icon(vectorResource(icon), contentDescription = null) + Spacer(Modifier.size(ButtonDefaults.IconSpacing)) + Text(stringResource(Res.string.theme)) + } + ) + + val uriHandler = LocalUriHandler.current + TextButton( + modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp) + .widthIn(min = 200.dp), + onClick = { uriHandler.openUri("https://github.com/terrakok") }, + ) { + Text(stringResource(Res.string.open_github)) + } + + Button( + onClick = { navigator.pushX(ScreenB()) }, + content = { Text("Go to Screen B") } + ) + } + } +} + +class ScreenB : Screen { + @Composable + override fun Content() { + val navigator = LocalNavigator.currentOrThrow + Column( + modifier = Modifier.fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text ="Screen B", + style = MaterialTheme.typography.headlineSmall + ) + Button( + onClick = { navigator.pushX(screen = ScreenC()) }, + content = { Text("Go to Screen C") } + ) + } + } +} + +class ScreenC : Screen { + @Composable + override fun Content() { + val navigator = LocalNavigator.currentOrThrow + val bottomSheetNavigator = LocalBottomSheetNavigator.current + Column( + modifier = Modifier.fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text ="Screen C", + style = MaterialTheme.typography.headlineSmall + ) + Button( + onClick = { navigator.popUntilRootX()}, + content = { Text("Go to Screen A - pop to root") } + ) + + Button( + onClick = { navigator.popX() }, + content = { Text("pop") } + ) + + Button( + onClick = { bottomSheetNavigator.showX(SampleBottomSheet()) }, + content = { Text("show bottom sheet") } + ) + } + } +} + +class SampleBottomSheet : Screen { + @Composable + override fun Content() { + + val bottomSheetNavigator = LocalBottomSheetNavigator.current + Column( + modifier = Modifier.fillMaxWidth(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = "Bottom Sheet", + style = MaterialTheme.typography.headlineSmall + ) + Button( + onClick = { bottomSheetNavigator.hideX() }, + content = { Text("Close") } + ) + } + } +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/kashif/sample/theme/Color.kt b/composeApp/src/commonMain/kotlin/com/kashif/sample/theme/Color.kt new file mode 100644 index 0000000..d3ba57b --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/kashif/sample/theme/Color.kt @@ -0,0 +1,71 @@ +package com.kashif.sample.theme + +import androidx.compose.ui.graphics.Color + +//generated by https://m3.material.io/theme-builder#/custom +//Color palette was taken here: https://colorhunt.co/palettes/popular + +internal val md_theme_light_primary = Color(0xFF00687A) +internal val md_theme_light_onPrimary = Color(0xFFFFFFFF) +internal val md_theme_light_primaryContainer = Color(0xFFABEDFF) +internal val md_theme_light_onPrimaryContainer = Color(0xFF001F26) +internal val md_theme_light_secondary = Color(0xFF00696E) +internal val md_theme_light_onSecondary = Color(0xFFFFFFFF) +internal val md_theme_light_secondaryContainer = Color(0xFF6FF6FE) +internal val md_theme_light_onSecondaryContainer = Color(0xFF002022) +internal val md_theme_light_tertiary = Color(0xFF904D00) +internal val md_theme_light_onTertiary = Color(0xFFFFFFFF) +internal val md_theme_light_tertiaryContainer = Color(0xFFFFDCC2) +internal val md_theme_light_onTertiaryContainer = Color(0xFF2E1500) +internal val md_theme_light_error = Color(0xFFBA1A1A) +internal val md_theme_light_errorContainer = Color(0xFFFFDAD6) +internal val md_theme_light_onError = Color(0xFFFFFFFF) +internal val md_theme_light_onErrorContainer = Color(0xFF410002) +internal val md_theme_light_background = Color(0xFFFFFBFF) +internal val md_theme_light_onBackground = Color(0xFF221B00) +internal val md_theme_light_surface = Color(0xFFFFFBFF) +internal val md_theme_light_onSurface = Color(0xFF221B00) +internal val md_theme_light_surfaceVariant = Color(0xFFDBE4E7) +internal val md_theme_light_onSurfaceVariant = Color(0xFF3F484B) +internal val md_theme_light_outline = Color(0xFF70797B) +internal val md_theme_light_inverseOnSurface = Color(0xFFFFF0C0) +internal val md_theme_light_inverseSurface = Color(0xFF3A3000) +internal val md_theme_light_inversePrimary = Color(0xFF55D6F4) +internal val md_theme_light_shadow = Color(0xFF000000) +internal val md_theme_light_surfaceTint = Color(0xFF00687A) +internal val md_theme_light_outlineVariant = Color(0xFFBFC8CB) +internal val md_theme_light_scrim = Color(0xFF000000) + +internal val md_theme_dark_primary = Color(0xFF55D6F4) +internal val md_theme_dark_onPrimary = Color(0xFF003640) +internal val md_theme_dark_primaryContainer = Color(0xFF004E5C) +internal val md_theme_dark_onPrimaryContainer = Color(0xFFABEDFF) +internal val md_theme_dark_secondary = Color(0xFF4CD9E2) +internal val md_theme_dark_onSecondary = Color(0xFF00373A) +internal val md_theme_dark_secondaryContainer = Color(0xFF004F53) +internal val md_theme_dark_onSecondaryContainer = Color(0xFF6FF6FE) +internal val md_theme_dark_tertiary = Color(0xFFFFB77C) +internal val md_theme_dark_onTertiary = Color(0xFF4D2700) +internal val md_theme_dark_tertiaryContainer = Color(0xFF6D3900) +internal val md_theme_dark_onTertiaryContainer = Color(0xFFFFDCC2) +internal val md_theme_dark_error = Color(0xFFFFB4AB) +internal val md_theme_dark_errorContainer = Color(0xFF93000A) +internal val md_theme_dark_onError = Color(0xFF690005) +internal val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6) +internal val md_theme_dark_background = Color(0xFF221B00) +internal val md_theme_dark_onBackground = Color(0xFFFFE264) +internal val md_theme_dark_surface = Color(0xFF221B00) +internal val md_theme_dark_onSurface = Color(0xFFFFE264) +internal val md_theme_dark_surfaceVariant = Color(0xFF3F484B) +internal val md_theme_dark_onSurfaceVariant = Color(0xFFBFC8CB) +internal val md_theme_dark_outline = Color(0xFF899295) +internal val md_theme_dark_inverseOnSurface = Color(0xFF221B00) +internal val md_theme_dark_inverseSurface = Color(0xFFFFE264) +internal val md_theme_dark_inversePrimary = Color(0xFF00687A) +internal val md_theme_dark_shadow = Color(0xFF000000) +internal val md_theme_dark_surfaceTint = Color(0xFF55D6F4) +internal val md_theme_dark_outlineVariant = Color(0xFF3F484B) +internal val md_theme_dark_scrim = Color(0xFF000000) + + +internal val seed = Color(0xFF2C3639) diff --git a/composeApp/src/commonMain/kotlin/com/kashif/sample/theme/Theme.kt b/composeApp/src/commonMain/kotlin/com/kashif/sample/theme/Theme.kt new file mode 100644 index 0000000..9243e4a --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/kashif/sample/theme/Theme.kt @@ -0,0 +1,95 @@ +package com.kashif.sample.theme + +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.* + +private val LightColorScheme = lightColorScheme( + primary = md_theme_light_primary, + onPrimary = md_theme_light_onPrimary, + primaryContainer = md_theme_light_primaryContainer, + onPrimaryContainer = md_theme_light_onPrimaryContainer, + secondary = md_theme_light_secondary, + onSecondary = md_theme_light_onSecondary, + secondaryContainer = md_theme_light_secondaryContainer, + onSecondaryContainer = md_theme_light_onSecondaryContainer, + tertiary = md_theme_light_tertiary, + onTertiary = md_theme_light_onTertiary, + tertiaryContainer = md_theme_light_tertiaryContainer, + onTertiaryContainer = md_theme_light_onTertiaryContainer, + error = md_theme_light_error, + errorContainer = md_theme_light_errorContainer, + onError = md_theme_light_onError, + onErrorContainer = md_theme_light_onErrorContainer, + background = md_theme_light_background, + onBackground = md_theme_light_onBackground, + surface = md_theme_light_surface, + onSurface = md_theme_light_onSurface, + surfaceVariant = md_theme_light_surfaceVariant, + onSurfaceVariant = md_theme_light_onSurfaceVariant, + outline = md_theme_light_outline, + inverseOnSurface = md_theme_light_inverseOnSurface, + inverseSurface = md_theme_light_inverseSurface, + inversePrimary = md_theme_light_inversePrimary, + surfaceTint = md_theme_light_surfaceTint, + outlineVariant = md_theme_light_outlineVariant, + scrim = md_theme_light_scrim, +) + +private val DarkColorScheme = darkColorScheme( + primary = md_theme_dark_primary, + onPrimary = md_theme_dark_onPrimary, + primaryContainer = md_theme_dark_primaryContainer, + onPrimaryContainer = md_theme_dark_onPrimaryContainer, + secondary = md_theme_dark_secondary, + onSecondary = md_theme_dark_onSecondary, + secondaryContainer = md_theme_dark_secondaryContainer, + onSecondaryContainer = md_theme_dark_onSecondaryContainer, + tertiary = md_theme_dark_tertiary, + onTertiary = md_theme_dark_onTertiary, + tertiaryContainer = md_theme_dark_tertiaryContainer, + onTertiaryContainer = md_theme_dark_onTertiaryContainer, + error = md_theme_dark_error, + errorContainer = md_theme_dark_errorContainer, + onError = md_theme_dark_onError, + onErrorContainer = md_theme_dark_onErrorContainer, + background = md_theme_dark_background, + onBackground = md_theme_dark_onBackground, + surface = md_theme_dark_surface, + onSurface = md_theme_dark_onSurface, + surfaceVariant = md_theme_dark_surfaceVariant, + onSurfaceVariant = md_theme_dark_onSurfaceVariant, + outline = md_theme_dark_outline, + inverseOnSurface = md_theme_dark_inverseOnSurface, + inverseSurface = md_theme_dark_inverseSurface, + inversePrimary = md_theme_dark_inversePrimary, + surfaceTint = md_theme_dark_surfaceTint, + outlineVariant = md_theme_dark_outlineVariant, + scrim = md_theme_dark_scrim, +) + +internal val LocalThemeIsDark = compositionLocalOf { mutableStateOf(true) } + +@Composable +internal fun AppTheme( + content: @Composable () -> Unit +) { + val systemIsDark = isSystemInDarkTheme() + val isDarkState = remember { mutableStateOf(systemIsDark) } + CompositionLocalProvider( + LocalThemeIsDark provides isDarkState + ) { + val isDark by isDarkState + SystemAppearance(!isDark) + MaterialTheme( + colorScheme = if (isDark) DarkColorScheme else LightColorScheme, + content = { Surface(content = content) } + ) + } +} + +@Composable +internal expect fun SystemAppearance(isDark: Boolean) diff --git a/composeApp/src/commonTest/kotlin/com/kashif/sample/ComposeTest.kt b/composeApp/src/commonTest/kotlin/com/kashif/sample/ComposeTest.kt new file mode 100644 index 0000000..0230290 --- /dev/null +++ b/composeApp/src/commonTest/kotlin/com/kashif/sample/ComposeTest.kt @@ -0,0 +1,45 @@ +package com.kashif.sample + +import androidx.compose.foundation.layout.Column +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.assertTextEquals +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.runComposeUiTest +import kotlin.test.Test + +@OptIn(ExperimentalTestApi::class) +class ComposeTest { + + @Test + fun simpleCheck() = runComposeUiTest { + setContent { + var txt by remember { mutableStateOf("Go") } + Column { + Text( + text = txt, + modifier = Modifier.testTag("t_text") + ) + Button( + onClick = { txt += "." }, + modifier = Modifier.testTag("t_button") + ) { + Text("click me") + } + } + } + + onNodeWithTag("t_button").apply { + repeat(3) { performClick() } + } + onNodeWithTag("t_text").assertTextEquals("Go...") + } +} \ No newline at end of file diff --git a/composeApp/src/iosMain/kotlin/com/kashif/sample/main.kt b/composeApp/src/iosMain/kotlin/com/kashif/sample/main.kt new file mode 100644 index 0000000..cac90f3 --- /dev/null +++ b/composeApp/src/iosMain/kotlin/com/kashif/sample/main.kt @@ -0,0 +1,7 @@ +package com.kashif.sample + + +import androidx.compose.ui.window.ComposeUIViewController +import platform.UIKit.UIViewController + +fun MainViewController(): UIViewController = ComposeUIViewController { App() } diff --git a/composeApp/src/iosMain/kotlin/com/kashif/sample/theme/Theme.ios.kt b/composeApp/src/iosMain/kotlin/com/kashif/sample/theme/Theme.ios.kt new file mode 100644 index 0000000..48ce56b --- /dev/null +++ b/composeApp/src/iosMain/kotlin/com/kashif/sample/theme/Theme.ios.kt @@ -0,0 +1,17 @@ +package com.kashif.sample.theme + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import platform.UIKit.UIApplication +import platform.UIKit.UIStatusBarStyleDarkContent +import platform.UIKit.UIStatusBarStyleLightContent +import platform.UIKit.setStatusBarStyle + +@Composable +internal actual fun SystemAppearance(isDark: Boolean) { + LaunchedEffect(isDark) { + UIApplication.sharedApplication.setStatusBarStyle( + if (isDark) UIStatusBarStyleDarkContent else UIStatusBarStyleLightContent + ) + } +} \ No newline at end of file diff --git a/convention-plugins/build.gradle.kts b/convention-plugins/build.gradle.kts new file mode 100644 index 0000000..c5a80b7 --- /dev/null +++ b/convention-plugins/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + `kotlin-dsl` // Is needed to turn our build logic written in Kotlin into Gralde Plugin +} + +repositories { + gradlePluginPortal() // To use 'maven-publish' and 'signing' plugins in our own plugin +} \ No newline at end of file diff --git a/convention-plugins/src/main/kotlin/convention.publication.gradle.kts b/convention-plugins/src/main/kotlin/convention.publication.gradle.kts new file mode 100644 index 0000000..adcd301 --- /dev/null +++ b/convention-plugins/src/main/kotlin/convention.publication.gradle.kts @@ -0,0 +1,99 @@ +//Publishing your Kotlin Multiplatform library to Maven Central +//https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-going-public-4a8k + +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.tasks.bundling.Jar +import org.gradle.kotlin.dsl.`maven-publish` +import org.gradle.kotlin.dsl.signing +import java.util.* + +plugins { + id("maven-publish") + id("signing") +} + +// Stub secrets to let the project sync and build without the publication values set up +ext["signing.keyId"] = null +ext["signing.password"] = null +ext["signing.secretKeyRingFile"] = null +ext["ossrhUsername"] = null +ext["ossrhPassword"] = null + +// Grabbing secrets from local.properties file or from environment variables, which could be used on CI +val secretPropsFile = project.rootProject.file("local.properties") +if (secretPropsFile.exists()) { + secretPropsFile.reader().use { + Properties().apply { load(it) } + }.onEach { (name, value) -> + ext[name.toString()] = value + } +} else { + ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID") + ext["signing.password"] = System.getenv("SIGNING_PASSWORD") + ext["signing.secretKeyRingFile"] = System.getenv("SIGNING_SECRET_KEY_RING_FILE") + ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME") + ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD") +} + +val javadocJar by tasks.registering(Jar::class) { + archiveClassifier.set("javadoc") +} + +fun getExtraString(name: String) = ext[name]?.toString() + +publishing { + // Configure maven central repository + repositories { + maven { + name = "sonatype" + setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") + credentials { + username = getExtraString("ossrhUsername") + password = getExtraString("ossrhPassword") + } + } + } + + // Configure all publications + publications.withType { + // Stub javadoc.jar artifact + artifact(javadocJar.get()) + + // Provide artifacts information requited by Maven Central + pom { + name.set("Voyant") + description.set("Kotlin Multiplatform library") + //url.set("") todo + + licenses { + license { + name.set("MIT") + url.set("https://opensource.org/licenses/MIT") + } + } + developers { + developer { + //id.set("") todo + //name.set("") todo + //email.set("") todo + } + } + scm { + //url.set("") todo + } + } + } +} + +// Signing artifacts. Signing.* extra properties values will be used +signing { + if (getExtraString("signing.keyId") != null) { + sign(publishing.publications) + } +} + +//https://github.com/gradle/gradle/issues/26132 +val signingTasks = tasks.withType() +tasks.withType().configureEach { + mustRunAfter(signingTasks) +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..97aeb6e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,14 @@ +#Gradle +org.gradle.jvmargs=-Xmx4G +org.gradle.caching=true +org.gradle.configuration-cache=true +org.gradle.daemon=true +org.gradle.parallel=true + +#Kotlin +kotlin.code.style=official +kotlin.daemon.jvmargs=-Xmx4G + +#Android +android.useAndroidX=true +android.nonTransitiveRClass=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..a3a5982 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,33 @@ +[versions] + +kotlin = "2.0.20" +agp = "8.5.2" +kotlinx-coroutines = "1.9.0" +compose = "1.7.0-beta02" +androidx-activityCompose = "1.9.2" +androidx-uiTest = "1.7.2" +voyager = "1.1.0-beta02" +napier = "2.7.1" + +[libraries] + +kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" } + +voyager-bottom-sheet-navigator = { module = "cafe.adriel.voyager:voyager-bottom-sheet-navigator", version.ref = "voyager" } +voyager-navigator = { module = "cafe.adriel.voyager:voyager-navigator", version.ref = "voyager" } +napier = { module = "io.github.aakira:napier", version.ref = "napier" } + + +androidx-activityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } +androidx-uitest-testManifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "androidx-uiTest" } +androidx-uitest-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "androidx-uiTest" } +[plugins] + +multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +android-library = { id = "com.android.library", version.ref = "agp" } +compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } +compose = { id = "org.jetbrains.compose", version.ref = "compose" } +android-application = { id = "com.android.application", version.ref = "agp" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e644113 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a6b6624 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,8 @@ +#Sat Sep 28 15:38:03 PKT 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..25da30d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/iosApp/iosApp.xcodeproj/project.pbxproj b/iosApp/iosApp.xcodeproj/project.pbxproj new file mode 100644 index 0000000..ca7e1ac --- /dev/null +++ b/iosApp/iosApp.xcodeproj/project.pbxproj @@ -0,0 +1,364 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + A93A953B29CC810C00F8E227 /* iosApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93A953A29CC810C00F8E227 /* iosApp.swift */; }; + A93A953F29CC810D00F8E227 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A93A953E29CC810D00F8E227 /* Assets.xcassets */; }; + A93A954229CC810D00F8E227 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A93A954129CC810D00F8E227 /* Preview Assets.xcassets */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + A93A953729CC810C00F8E227 /* IosNavigationINComposeMultiplatform.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = IosNavigationINComposeMultiplatform.app; sourceTree = BUILT_PRODUCTS_DIR; }; + A93A953A29CC810C00F8E227 /* iosApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iosApp.swift; sourceTree = ""; }; + A93A953E29CC810D00F8E227 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + A93A954129CC810D00F8E227 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + A93A953429CC810C00F8E227 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + A93A952E29CC810C00F8E227 = { + isa = PBXGroup; + children = ( + A93A953929CC810C00F8E227 /* iosApp */, + A93A953829CC810C00F8E227 /* Products */, + C4127409AE3703430489E7BC /* Frameworks */, + ); + sourceTree = ""; + }; + A93A953829CC810C00F8E227 /* Products */ = { + isa = PBXGroup; + children = ( + A93A953729CC810C00F8E227 /* IosNavigationINComposeMultiplatform.app */, + ); + name = Products; + sourceTree = ""; + }; + A93A953929CC810C00F8E227 /* iosApp */ = { + isa = PBXGroup; + children = ( + A93A953A29CC810C00F8E227 /* iosApp.swift */, + A93A953E29CC810D00F8E227 /* Assets.xcassets */, + A93A954029CC810D00F8E227 /* Preview Content */, + ); + path = iosApp; + sourceTree = ""; + }; + A93A954029CC810D00F8E227 /* Preview Content */ = { + isa = PBXGroup; + children = ( + A93A954129CC810D00F8E227 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; + C4127409AE3703430489E7BC /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + A93A953629CC810C00F8E227 /* iosApp */ = { + isa = PBXNativeTarget; + buildConfigurationList = A93A954529CC810D00F8E227 /* Build configuration list for PBXNativeTarget "iosApp" */; + buildPhases = ( + A9D80A052AAB5CDE006C8738 /* ShellScript */, + A93A953329CC810C00F8E227 /* Sources */, + A93A953429CC810C00F8E227 /* Frameworks */, + A93A953529CC810C00F8E227 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = iosApp; + productName = iosApp; + productReference = A93A953729CC810C00F8E227 /* IosNavigationINComposeMultiplatform.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + A93A952F29CC810C00F8E227 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1420; + LastUpgradeCheck = 1420; + TargetAttributes = { + A93A953629CC810C00F8E227 = { + CreatedOnToolsVersion = 14.2; + }; + }; + }; + buildConfigurationList = A93A953229CC810C00F8E227 /* Build configuration list for PBXProject "iosApp" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = A93A952E29CC810C00F8E227; + productRefGroup = A93A953829CC810C00F8E227 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + A93A953629CC810C00F8E227 /* iosApp */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + A93A953529CC810C00F8E227 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A93A954229CC810D00F8E227 /* Preview Assets.xcassets in Resources */, + A93A953F29CC810D00F8E227 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + A9D80A052AAB5CDE006C8738 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "cd \"$SRCROOT/..\"\n./gradlew :composeApp:embedAndSignAppleFrameworkForXcode\n"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + A93A953329CC810C00F8E227 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A93A953B29CC810C00F8E227 /* iosApp.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + A93A954329CC810D00F8E227 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.2; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + A93A954429CC810D00F8E227 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.2; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + A93A954629CC810D00F8E227 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\""; + DEVELOPMENT_TEAM = 82SP652DFP; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = iosApp/Info.plist; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.2; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.kashif.sample.iosApp; + PRODUCT_NAME = IosNavigationINComposeMultiplatform; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + A93A954729CC810D00F8E227 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\""; + DEVELOPMENT_TEAM = 82SP652DFP; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = iosApp/Info.plist; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.2; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.kashif.sample.iosApp; + PRODUCT_NAME = IosNavigationINComposeMultiplatform; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + A93A953229CC810C00F8E227 /* Build configuration list for PBXProject "iosApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A93A954329CC810D00F8E227 /* Debug */, + A93A954429CC810D00F8E227 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + A93A954529CC810D00F8E227 /* Build configuration list for PBXNativeTarget "iosApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A93A954629CC810D00F8E227 /* Debug */, + A93A954729CC810D00F8E227 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = A93A952F29CC810C00F8E227 /* Project object */; +} diff --git a/iosApp/iosApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/iosApp/iosApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/iosApp/iosApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json b/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..13613e3 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,13 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Assets.xcassets/Contents.json b/iosApp/iosApp/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Info.plist b/iosApp/iosApp/Info.plist new file mode 100644 index 0000000..11845e1 --- /dev/null +++ b/iosApp/iosApp/Info.plist @@ -0,0 +1,8 @@ + + + + + CADisableMinimumFrameDurationOnPhone + + + diff --git a/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json b/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/iosApp.swift b/iosApp/iosApp/iosApp.swift new file mode 100644 index 0000000..8a1ecc4 --- /dev/null +++ b/iosApp/iosApp/iosApp.swift @@ -0,0 +1,24 @@ +import UIKit +import ComposeApp + +@main +class AppDelegate: UIResponder, UIApplicationDelegate { + var window: UIWindow? + + func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + window = UIWindow(frame: UIScreen.main.bounds) + if let window = window { + let uiController = UINavigationController( rootViewController: MainKt.MainViewController()) + uiController.interactivePopGestureRecognizer?.isEnabled = true + window.rootViewController = uiController + + window.makeKeyAndVisible() + } + + + return true + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..3614220 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,34 @@ +rootProject.name = "Voyant" + +pluginManagement { + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + includeGroupByRegex("android.*") + } + } + gradlePluginPortal() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + includeGroupByRegex("android.*") + } + } + mavenCentral() + } +} +includeBuild("convention-plugins") +include(":voyagerX") +include(":composeApp") + diff --git a/voyagerX/build.gradle.kts b/voyagerX/build.gradle.kts new file mode 100644 index 0000000..7baf0f2 --- /dev/null +++ b/voyagerX/build.gradle.kts @@ -0,0 +1,75 @@ +plugins { + alias(libs.plugins.multiplatform) + alias(libs.plugins.android.library) + id("convention.publication") + alias(libs.plugins.compose.compiler) + alias(libs.plugins.compose) +} + +group = "com.kashif.voyant" +version = "1.0" + +kotlin { + jvmToolchain(11) + androidTarget { + publishLibraryVariants("release") + } + + jvm() + + wasmJs { + browser() + binaries.executable() + } + + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64() + ).forEach { + it.binaries.framework { + baseName = "voyagerX" + isStatic = true + } + } + + sourceSets { + commonMain.dependencies { + implementation(libs.kotlinx.coroutines.core) + implementation(libs.kotlinx.coroutines.test) + implementation(compose.ui) + implementation(compose.foundation) + implementation(compose.material) + api(libs.voyager.navigator) + api(libs.voyager.bottom.sheet.navigator) + } + + commonTest.dependencies { + implementation(kotlin("test")) + } + + androidMain.dependencies { + implementation(libs.kotlinx.coroutines.android) + } + + jvmMain.dependencies { + implementation(libs.kotlinx.coroutines.swing) + } + + } + + //https://kotlinlang.org/docs/native-objc-interop.html#export-of-kdoc-comments-to-generated-objective-c-headers + targets.withType { + compilations["main"].compilerOptions.options.freeCompilerArgs.add("-Xexport-kdoc") + } + +} + +android { + namespace = "com.kashif.voyant" + compileSdk = 35 + + defaultConfig { + minSdk = 21 + } +} diff --git a/voyagerX/src/androidMain/kotlin/com/kashif/voyant/Extensions.android.kt b/voyagerX/src/androidMain/kotlin/com/kashif/voyant/Extensions.android.kt new file mode 100644 index 0000000..f92cbd9 --- /dev/null +++ b/voyagerX/src/androidMain/kotlin/com/kashif/voyant/Extensions.android.kt @@ -0,0 +1,25 @@ +package com.kashif.voyant + +import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.navigator.Navigator +import cafe.adriel.voyager.navigator.bottomSheet.BottomSheetNavigator + +actual fun Navigator.popX() { + pop() +} + +actual fun Navigator.pushX(screen: Screen) { + push(screen) +} + +actual fun Navigator.popUntilRootX() { + popUntilRoot() +} + +actual fun BottomSheetNavigator.showX(screen: Screen) { + show(screen) +} + +actual fun BottomSheetNavigator.hideX() { + hide() +} \ No newline at end of file diff --git a/voyagerX/src/appleMain/kotlin/com/kashif/voyant/Extensions.apple.kt b/voyagerX/src/appleMain/kotlin/com/kashif/voyant/Extensions.apple.kt new file mode 100644 index 0000000..4baa30b --- /dev/null +++ b/voyagerX/src/appleMain/kotlin/com/kashif/voyant/Extensions.apple.kt @@ -0,0 +1,87 @@ +package com.kashif.voyant + + +import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.navigator.Navigator +import cafe.adriel.voyager.navigator.bottomSheet.BottomSheetNavigator +import com.kashif.voyant.extensions.extendedComposeViewController +import com.kashif.voyant.extensions.getTopViewController +import platform.Foundation.NSLog +import platform.UIKit.UIGestureRecognizerDelegateProtocol +import platform.UIKit.UINavigationController +import platform.UIKit.UINavigationControllerDelegateProtocol +import platform.UIKit.hidesBottomBarWhenPushed +import platform.UIKit.navigationController + +/** + * Pushes a new screen onto the navigation stack. + * + * @param screen The screen to be pushed. + */ +actual fun Navigator.pushX(screen: Screen) { + val viewController = extendedComposeViewController(screen = screen) + viewController.hidesBottomBarWhenPushed = true + + val navigationController = getNavigationController() + navigationController?.let { navController -> + navController.pushViewController(viewController, animated = true) + // Enable the gesture recognizer after pushing and set its delegate + navController.interactivePopGestureRecognizer?.setEnabled(true) + navController.interactivePopGestureRecognizer?.delegate = viewController as? UIGestureRecognizerDelegateProtocol + } ?: run { + NSLog("NavigationController is null") + } +} + +/** + * Pops the top screen from the navigation stack. + */ +actual fun Navigator.popX() { + val navigationController = getNavigationController() + navigationController?.let { navController -> + if (navController.viewControllers.size > 1) { + navController.popViewControllerAnimated(true) + } else { + NSLog("Cannot pop. Only one view controller in the stack.") + } + } ?: run { + NSLog("NavigationController is null") + } +} + +/** + * Pops all the screens on the navigation stack until the root screen is at the top. + */ +actual fun Navigator.popUntilRootX() { + val navigationController = getNavigationController() + navigationController?.popToRootViewControllerAnimated(true) ?: run { + NSLog("NavigationController is null") + } +} + +/** + * Retrieves the top `UINavigationController` from the view hierarchy. + * + * @return The top `UINavigationController`, or null if none is found. + */ +fun getNavigationController(): UINavigationController? { + val topVc = getTopViewController() + return topVc?.let { topViewController -> + topViewController as? UINavigationController ?: topViewController.navigationController + } +} + +actual fun BottomSheetNavigator.hideX() { + val topVc = getTopViewController() + topVc?.dismissViewControllerAnimated(true, null) ?: run { + NSLog("TopViewController is null") + } +} + +actual fun BottomSheetNavigator.showX(screen: Screen) { + val viewController = extendedComposeViewController(screen = screen) + val topVc = getTopViewController() + topVc?.presentViewController(viewController, animated = true, completion = null) ?: run { + NSLog("TopViewController is null") + } +} \ No newline at end of file diff --git a/voyagerX/src/appleMain/kotlin/com/kashif/voyant/extensions/UIVIewControllerExtensions.kt b/voyagerX/src/appleMain/kotlin/com/kashif/voyant/extensions/UIVIewControllerExtensions.kt new file mode 100644 index 0000000..55986c8 --- /dev/null +++ b/voyagerX/src/appleMain/kotlin/com/kashif/voyant/extensions/UIVIewControllerExtensions.kt @@ -0,0 +1,118 @@ +package com.kashif.voyant.extensions + + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.asPaddingValues +import androidx.compose.foundation.layout.imePadding +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.safeDrawing +import androidx.compose.material.ExperimentalMaterialApi +import androidx.compose.runtime.ExperimentalComposeApi +import androidx.compose.ui.Modifier +import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.uikit.OnFocusBehavior +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.ComposeUIViewController +import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.navigator.Navigator +import cafe.adriel.voyager.navigator.bottomSheet.BottomSheetNavigator +import platform.Foundation.NSLog +import platform.UIKit.UIApplication +import platform.UIKit.UINavigationController +import platform.UIKit.UITabBarController +import platform.UIKit.UIViewController +import platform.UIKit.childViewControllers + +/** + * Retrieves the top `UIViewController` from the view hierarchy. + * + * @param base The base `UIViewController` to start the search from. Defaults to the root view controller of the key window. + * @return The top `UIViewController`, or null if none is found. + */ +fun getTopViewController(base: UIViewController? = UIApplication.sharedApplication().keyWindow?.rootViewController): UIViewController? { + when { + base is UINavigationController -> { + return getTopViewController(base = base.visibleViewController) + } + + base is UITabBarController -> { + return getTopViewController(base = base.selectedViewController) + } + + base?.presentedViewController != null -> { + return getTopViewController(base = base.presentedViewController) + } + + base.toString().contains("HostingController") -> return getTopViewController( + base = base?.childViewControllers()?.first() as UIViewController + ) + + else -> { + return base + } + } +} + +/** + * Logs the hierarchy of the top `UIViewController` for debugging purposes. + * + * @param base The base `UIViewController` to start the search from. Defaults to the root view controller of the key window. + */ +fun debugTopViewController(base: UIViewController? = UIApplication.sharedApplication().keyWindow?.rootViewController) { + if (base is UINavigationController) { + NSLog("TopViewController: UINavigationController with visible view controller: ${base.visibleViewController}") + debugTopViewController(base = base.visibleViewController) + } else if (base is UITabBarController) { + NSLog("TopViewController: UITabBarController with selected view controller: ${base.selectedViewController}") + debugTopViewController(base = base.selectedViewController) + } else if (base?.presentedViewController != null) { + NSLog("TopViewController: Presented view controller: ${base.presentedViewController}") + debugTopViewController(base = base.presentedViewController) + } else { + NSLog("TopViewController: ${base}") + } +} + +/** + * Creates a `UIViewController` that hosts a Compose UI. + * + * @param modifier The `Modifier` to be applied to the Compose UI. + * @param screen The `Screen` to be displayed in the Compose UI. + * @param isOpaque Whether the view controller's view is opaque. + * @return A `UIViewController` that hosts the Compose UI. + */ +@OptIn(ExperimentalComposeApi::class, ExperimentalMaterialApi::class) +fun extendedComposeViewController( + modifier: Modifier = Modifier, + screen: Screen, + isOpaque: Boolean = true, +): UIViewController { + val uiViewController = ComposeUIViewController(configure = { + onFocusBehavior = OnFocusBehavior.DoNothing + opaque = isOpaque + }) { + + Box(modifier = modifier.imePadding() + .padding(top = WindowInsets.safeDrawing.asPaddingValues().calculateTopPadding()) + .pointerInput(Unit) { + awaitPointerEventScope { + while (true) { + val event = awaitPointerEvent() + val position = event.changes.first().position + // Don't consume events within 50.dp from the left edge + if (position.x > 50.dp.toPx()) { + event.changes.forEach { it.consume() } + } + } + } + } + ) { + BottomSheetNavigator { + Navigator(screen = screen) + } + } + } + + return UIViewControllerWrapper(uiViewController) +} \ No newline at end of file diff --git a/voyagerX/src/appleMain/kotlin/com/kashif/voyant/extensions/UIViewControllerWrapper.kt b/voyagerX/src/appleMain/kotlin/com/kashif/voyant/extensions/UIViewControllerWrapper.kt new file mode 100644 index 0000000..840d161 --- /dev/null +++ b/voyagerX/src/appleMain/kotlin/com/kashif/voyant/extensions/UIViewControllerWrapper.kt @@ -0,0 +1,135 @@ +package com.kashif.voyant.extensions + + +import kotlinx.cinterop.BetaInteropApi +import kotlinx.cinterop.ExperimentalForeignApi +import kotlinx.cinterop.ObjCAction +import platform.Foundation.NSLog +import platform.Foundation.NSSelectorFromString +import platform.UIKit.UIEvent +import platform.UIKit.UIGestureRecognizer +import platform.UIKit.UIGestureRecognizerDelegateProtocol +import platform.UIKit.UINavigationController +import platform.UIKit.UINavigationControllerDelegateProtocol +import platform.UIKit.UIPress +import platform.UIKit.UISwipeGestureRecognizer +import platform.UIKit.UISwipeGestureRecognizerDirectionLeft +import platform.UIKit.UISwipeGestureRecognizerDirectionRight +import platform.UIKit.UITouch +import platform.UIKit.UIViewController +import platform.UIKit.addChildViewController +import platform.UIKit.didMoveToParentViewController +import platform.UIKit.navigationController +import platform.UIKit.willMoveToParentViewController + +/** + * A custom `UIViewController` that wraps another `UIViewController` and adds gesture recognizer functionality. + * Implements the `UIGestureRecognizerDelegateProtocol` to handle swipe gestures. + * + * @property controller The `UIViewController` instance that is being wrapped. + */ +class UIViewControllerWrapper( + private val controller: UIViewController, +) : UIViewController(null, null), UIGestureRecognizerDelegateProtocol, + UINavigationControllerDelegateProtocol { + + /** + * Called when the view controller's view is loaded into memory. + * Sets up the view hierarchy by adding the wrapped controller's view as a subview + * and managing the parent-child relationship between the view controllers. + */ + @OptIn(ExperimentalForeignApi::class) + override fun loadView() { + super.loadView() + controller.willMoveToParentViewController(this) + controller.view.setFrame(view.frame) + view.addSubview(controller.view) + addChildViewController(controller) + controller.didMoveToParentViewController(this) + } + + /** + * Called after the view has been loaded. + * Sets the delegate for the interactive pop gesture recognizer and adds swipe gesture recognizers + * for left and right swipe directions. + */ + @OptIn(ExperimentalForeignApi::class) + override fun viewDidLoad() { + super.viewDidLoad() + navigationController?.interactivePopGestureRecognizer?.delegate = this + } + + /** + * Handles the swipe gestures detected by the gesture recognizers. + * Logs the direction of the swipe. + * + * @param sender The `UISwipeGestureRecognizer` that detected the swipe. + */ + @OptIn(BetaInteropApi::class) + @ObjCAction + fun handleSwipe(sender: UISwipeGestureRecognizer) { + NSLog("Swipe detected: ${sender.direction}") + } + + + /** + * Determines whether the gesture recognizer should receive an object representing a touch. + * Always returns `true`. + * + * @param gestureRecognizer The `UIGestureRecognizer` that is asking whether it should receive the touch. + * @param shouldReceiveTouch The `UITouch` object representing the touch. + * @return `true` to allow the gesture recognizer to receive the touch. + */ + override fun gestureRecognizer( + gestureRecognizer: UIGestureRecognizer, + shouldReceiveEvent: UIEvent + ): Boolean { + println("gestureRecognizer shouldReceiveEvent") + return true + } + + /** + * This method is called for press events + */ + override fun gestureRecognizer( + gestureRecognizer: UIGestureRecognizer, + shouldReceivePress: UIPress + ): Boolean { + println("gestureRecognizer shouldReceivePress") + return true + } + + + override fun navigationController( + navigationController: UINavigationController, + willShowViewController: UIViewController, + animated: Boolean + ) { + // Enable the gesture recognizer when pushing or popping view controllers + navigationController.interactivePopGestureRecognizer?.setEnabled(navigationController.viewControllers.size > 1) + } + + + override fun gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer): Boolean { + println("gestureRecognizerShouldBegin") + if (gestureRecognizer == navigationController?.interactivePopGestureRecognizer) { + return navigationController?.viewControllers?.size ?: 0 > 1 + } + return true + } + + override fun gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch: UITouch): Boolean { + println("gestureRecognizer shouldReceiveTouch") + return true + } + + override fun gestureRecognizer( + gestureRecognizer: UIGestureRecognizer, + shouldRequireFailureOfGestureRecognizer: UIGestureRecognizer + ): Boolean { + println("gestureRecognizer shouldRequireFailureOfGestureRecognizer") + // Change this to return true for the navigation gesture + return gestureRecognizer == navigationController?.interactivePopGestureRecognizer + } + +} \ No newline at end of file diff --git a/voyagerX/src/commonMain/kotlin/com/kashif/voyant/Extensions.kt b/voyagerX/src/commonMain/kotlin/com/kashif/voyant/Extensions.kt new file mode 100644 index 0000000..646f271 --- /dev/null +++ b/voyagerX/src/commonMain/kotlin/com/kashif/voyant/Extensions.kt @@ -0,0 +1,15 @@ +package com.kashif.voyant + +import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.navigator.Navigator +import cafe.adriel.voyager.navigator.bottomSheet.BottomSheetNavigator + +expect fun Navigator.popX() + +expect fun Navigator.pushX(screen: Screen) + +expect fun Navigator.popUntilRootX() + +expect fun BottomSheetNavigator.hideX() + +expect fun BottomSheetNavigator.showX(screen: Screen) \ No newline at end of file diff --git a/voyagerX/src/commonTest/kotlin/com/kashif/voyant/FibonacciTest.kt b/voyagerX/src/commonTest/kotlin/com/kashif/voyant/FibonacciTest.kt new file mode 100644 index 0000000..795aef6 --- /dev/null +++ b/voyagerX/src/commonTest/kotlin/com/kashif/voyant/FibonacciTest.kt @@ -0,0 +1,18 @@ +package com.kashif.voyant + +import kotlin.test.* + +class FibonacciTest { + + @Test + fun testFibonacciNumbers() { + assertFails { + getFibonacciNumbers(-1) + } + assertEquals( + listOf(0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377), + getFibonacciNumbers(15) + ) + } + +} \ No newline at end of file diff --git a/voyagerX/src/jvmMain/kotlin/com/kashif/voyant/Extensions.jvm.kt b/voyagerX/src/jvmMain/kotlin/com/kashif/voyant/Extensions.jvm.kt new file mode 100644 index 0000000..f92cbd9 --- /dev/null +++ b/voyagerX/src/jvmMain/kotlin/com/kashif/voyant/Extensions.jvm.kt @@ -0,0 +1,25 @@ +package com.kashif.voyant + +import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.navigator.Navigator +import cafe.adriel.voyager.navigator.bottomSheet.BottomSheetNavigator + +actual fun Navigator.popX() { + pop() +} + +actual fun Navigator.pushX(screen: Screen) { + push(screen) +} + +actual fun Navigator.popUntilRootX() { + popUntilRoot() +} + +actual fun BottomSheetNavigator.showX(screen: Screen) { + show(screen) +} + +actual fun BottomSheetNavigator.hideX() { + hide() +} \ No newline at end of file diff --git a/voyagerX/src/wasmJsMain/kotlin/com/kashif/voyant/Extensions.wasmJs.kt b/voyagerX/src/wasmJsMain/kotlin/com/kashif/voyant/Extensions.wasmJs.kt new file mode 100644 index 0000000..f92cbd9 --- /dev/null +++ b/voyagerX/src/wasmJsMain/kotlin/com/kashif/voyant/Extensions.wasmJs.kt @@ -0,0 +1,25 @@ +package com.kashif.voyant + +import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.navigator.Navigator +import cafe.adriel.voyager.navigator.bottomSheet.BottomSheetNavigator + +actual fun Navigator.popX() { + pop() +} + +actual fun Navigator.pushX(screen: Screen) { + push(screen) +} + +actual fun Navigator.popUntilRootX() { + popUntilRoot() +} + +actual fun BottomSheetNavigator.showX(screen: Screen) { + show(screen) +} + +actual fun BottomSheetNavigator.hideX() { + hide() +} \ No newline at end of file