From 87efc5a76e07cc93b6358d2d205607222a8a13a0 Mon Sep 17 00:00:00 2001 From: Ryan Moelter Date: Sun, 2 May 2021 15:20:15 -0700 Subject: [PATCH 1/6] Create a compose-based Step --- .travis.yml | 4 +- buildSrc/build.gradle | 4 +- buildSrc/src/main/kotlin/Dependencies.kt | 6 ++ buildSrc/src/main/kotlin/Versions.kt | 5 +- gradle/wrapper/gradle-wrapper.properties | 2 +- magellan-compose/.gitignore | 1 + magellan-compose/build.gradle | 69 +++++++++++++++++++ magellan-compose/gradle.properties | 4 ++ .../compose/ExampleInstrumentedTest.kt | 25 +++++++ magellan-compose/src/main/AndroidManifest.xml | 7 ++ .../magellan/compose/ComposeExtensions.kt | 9 +++ .../magellan/compose/ComposeInterop.kt | 49 +++++++++++++ .../example/magellan/compose/ComposeStep.kt | 21 ++++++ .../magellan/compose/SimpleComposeStep.kt | 11 +++ .../magellan/compose/ExampleUnitTest.kt | 18 +++++ settings.gradle | 1 + 16 files changed, 229 insertions(+), 7 deletions(-) create mode 100644 magellan-compose/.gitignore create mode 100644 magellan-compose/build.gradle create mode 100644 magellan-compose/gradle.properties create mode 100644 magellan-compose/src/androidTest/java/com/example/magellan/compose/ExampleInstrumentedTest.kt create mode 100644 magellan-compose/src/main/AndroidManifest.xml create mode 100644 magellan-compose/src/main/java/com/example/magellan/compose/ComposeExtensions.kt create mode 100644 magellan-compose/src/main/java/com/example/magellan/compose/ComposeInterop.kt create mode 100644 magellan-compose/src/main/java/com/example/magellan/compose/ComposeStep.kt create mode 100644 magellan-compose/src/main/java/com/example/magellan/compose/SimpleComposeStep.kt create mode 100644 magellan-compose/src/test/java/com/example/magellan/compose/ExampleUnitTest.kt diff --git a/.travis.yml b/.travis.yml index f4185af6..08271aba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ android: components: - tools - platform-tools - - build-tools-29.0.2 - - android-29 + - build-tools-30.0.2 + - android-30 - extra before_install: diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 8bce6e09..44ddf111 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.jetbrains.kotlin.jvm' version '1.3.72' + id 'org.jetbrains.kotlin.jvm' version '1.4.30' } repositories { @@ -9,7 +9,7 @@ repositories { } dependencies { - implementation "com.android.tools.build:gradle:4.1.1" + implementation "com.android.tools.build:gradle:7.0.0-alpha15" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 999357a0..5917646b 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -1,5 +1,6 @@ import Versions.archVersion import Versions.butterKnifeVersion +import Versions.composeVersion import Versions.coroutinesVersion import Versions.daggerVersion import Versions.espressoVersion @@ -52,6 +53,11 @@ object Dependencies { const val coroutinesAndroid = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" const val coroutinesTest = "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion" + const val composeUi = "androidx.compose.ui:ui:$composeVersion" + const val composeUiTooling = "androidx.compose.ui:ui-tooling:$composeVersion" + const val composeFoundation = "androidx.compose.foundation:foundation:$composeVersion" + const val composeMaterial = "androidx.compose.material:material:$composeVersion" + const val glide = "com.github.bumptech.glide:glide:$glideVersion" const val retrofit = "com.squareup.retrofit2:retrofit:$retrofitVersion" const val rxjava = "io.reactivex:rxjava:$rxjavaVersion" diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index ab03da7c..c811d628 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -1,11 +1,11 @@ object Versions { const val compileSdkVersion = 30 - const val minSdkVersion = 15 + const val minSdkVersion = 21 const val targetSdkVersion = 30 const val kotlinVersion = "1.4.30" const val kotlinterVersion = "3.4.0" - const val buildToolsVersion = "29.0.2" + const val buildToolsVersion = "30.0.2" const val detektVersion = "1.5.1" const val supportLibVersion = "1.1.0" const val robolectricVersion = "4.3.1" @@ -25,6 +25,7 @@ object Versions { const val javaInjectVersion = "1" const val materialVersion = "1.1.0" const val coroutinesVersion = "1.4.3" + const val composeVersion = "1.0.0-beta01" const val testCoreVersion = "1.2.0" const val junitVersion = "4.13" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4a14f202..ccbe0a4a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip diff --git a/magellan-compose/.gitignore b/magellan-compose/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/magellan-compose/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/magellan-compose/build.gradle b/magellan-compose/build.gradle new file mode 100644 index 00000000..873a5ac7 --- /dev/null +++ b/magellan-compose/build.gradle @@ -0,0 +1,69 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' + +group = GROUP +version = VERSION_NAME + +android { + compileSdkVersion Versions.compileSdkVersion + buildToolsVersion Versions.buildToolsVersion + + resourcePrefix 'magellan_' + + defaultConfig { + minSdkVersion Versions.minSdkVersion + targetSdkVersion Versions.targetSdkVersion + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildFeatures { + compose true + } + + composeOptions { + kotlinCompilerExtensionVersion Versions.composeVersion + } + + compileOptions { + setSourceCompatibility(JavaVersion.VERSION_1_8) + setTargetCompatibility(JavaVersion.VERSION_1_8) + } + + buildTypes { + release { + minifyEnabled false + } + } +} + +tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { + if (!name.contains("UnitTest")) { + kotlinOptions.freeCompilerArgs = ['-Xjvm-default=compatibility', '-Xexplicit-api=strict', '-Xopt-in=kotlin.RequiresOptIn'] + } + kotlinOptions.allWarningsAsErrors = true + kotlinOptions.jvmTarget = "1.8" +} + +dependencies { + implementation project(':magellan-library') + + implementation Dependencies.appCompat + implementation Dependencies.kotlinStdLib + implementation Dependencies.inject + implementation Dependencies.coroutines + implementation Dependencies.coroutinesAndroid + implementation Dependencies.composeUi + implementation Dependencies.composeUiTooling + implementation Dependencies.composeFoundation + + testImplementation Dependencies.testCore + testImplementation Dependencies.junit + testImplementation Dependencies.truth + testImplementation Dependencies.mockito + testImplementation Dependencies.robolectric +} + +apply from: rootProject.file('gradle/gradle-mvn-push.gradle') diff --git a/magellan-compose/gradle.properties b/magellan-compose/gradle.properties new file mode 100644 index 00000000..5991bca3 --- /dev/null +++ b/magellan-compose/gradle.properties @@ -0,0 +1,4 @@ +POM_ARTIFACT_ID=magellan-compose +POM_NAME=Magellan Compose +POM_DESCRIPTION=Compose support for Magellan +POM_PACKAGING=aar \ No newline at end of file diff --git a/magellan-compose/src/androidTest/java/com/example/magellan/compose/ExampleInstrumentedTest.kt b/magellan-compose/src/androidTest/java/com/example/magellan/compose/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..1f20bdc7 --- /dev/null +++ b/magellan-compose/src/androidTest/java/com/example/magellan/compose/ExampleInstrumentedTest.kt @@ -0,0 +1,25 @@ +package com.example.magellan.compose + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.magellan.compose.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/magellan-compose/src/main/AndroidManifest.xml b/magellan-compose/src/main/AndroidManifest.xml new file mode 100644 index 00000000..c846df87 --- /dev/null +++ b/magellan-compose/src/main/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/magellan-compose/src/main/java/com/example/magellan/compose/ComposeExtensions.kt b/magellan-compose/src/main/java/com/example/magellan/compose/ComposeExtensions.kt new file mode 100644 index 00000000..732f53ba --- /dev/null +++ b/magellan-compose/src/main/java/com/example/magellan/compose/ComposeExtensions.kt @@ -0,0 +1,9 @@ +package com.example.magellan.compose + +import androidx.compose.runtime.Composable +import com.wealthfront.magellan.core.Displayable + +@Composable +public fun Displayable(displayable: Displayable<@Composable () -> Unit>) { + displayable.view!!() +} diff --git a/magellan-compose/src/main/java/com/example/magellan/compose/ComposeInterop.kt b/magellan-compose/src/main/java/com/example/magellan/compose/ComposeInterop.kt new file mode 100644 index 00000000..caa4742b --- /dev/null +++ b/magellan-compose/src/main/java/com/example/magellan/compose/ComposeInterop.kt @@ -0,0 +1,49 @@ +package com.example.magellan.compose + +import android.view.View +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.viewinterop.AndroidView +import com.wealthfront.magellan.core.Displayable +import com.wealthfront.magellan.core.Navigable +import com.wealthfront.magellan.lifecycle.LifecycleAwareComponent +import com.wealthfront.magellan.lifecycle.lifecycle +import com.wealthfront.magellan.lifecycle.lifecycleWithContext + +@Composable +public fun Displayable(displayable: Displayable, modifier: Modifier = Modifier) { + AndroidView(modifier = modifier, factory = { + if (displayable.view == null) { + throw IllegalStateException( + "View does not exist on ${displayable::class.java.simpleName}. " + + "Is it attached to the lifecycle?" + ) + } + displayable.view!! + }) +} + +public class ComposeStepWrapper( + composeStep: Navigable<@Composable () -> Unit> +) : LifecycleAwareComponent(), Navigable { + + public val composeStep: Navigable<@Composable () -> Unit> by lifecycle(composeStep) + + override val view: View? by lifecycleWithContext { context -> + ComposeView(context).apply { + setContent @Composable { composeStep.view!!() } + } + } +} + +public class ViewStepComposer( + viewStep: Navigable +) : LifecycleAwareComponent(), Navigable<@Composable () -> Unit> { + + public val viewStep: Navigable by lifecycle(viewStep) + + override val view: @Composable () -> Unit = { + Displayable(viewStep) + } +} diff --git a/magellan-compose/src/main/java/com/example/magellan/compose/ComposeStep.kt b/magellan-compose/src/main/java/com/example/magellan/compose/ComposeStep.kt new file mode 100644 index 00000000..b53875ac --- /dev/null +++ b/magellan-compose/src/main/java/com/example/magellan/compose/ComposeStep.kt @@ -0,0 +1,21 @@ +package com.example.magellan.compose + +import androidx.annotation.VisibleForTesting +import androidx.compose.runtime.Composable +import com.wealthfront.magellan.core.Navigable +import com.wealthfront.magellan.coroutines.ShownLifecycleScope +import com.wealthfront.magellan.lifecycle.LifecycleAwareComponent +import com.wealthfront.magellan.lifecycle.lifecycle +import kotlinx.coroutines.CoroutineScope + +public abstract class ComposeStep : LifecycleAwareComponent(), Navigable<@Composable () -> Unit> { + + override val view: (@Composable () -> Unit)? + get() = { Compose() } + + public var shownScope: CoroutineScope by lifecycle(ShownLifecycleScope()) { it } + @VisibleForTesting set + + @Composable + public abstract fun Compose() +} \ No newline at end of file diff --git a/magellan-compose/src/main/java/com/example/magellan/compose/SimpleComposeStep.kt b/magellan-compose/src/main/java/com/example/magellan/compose/SimpleComposeStep.kt new file mode 100644 index 00000000..bb064c2b --- /dev/null +++ b/magellan-compose/src/main/java/com/example/magellan/compose/SimpleComposeStep.kt @@ -0,0 +1,11 @@ +package com.example.magellan.compose + +import androidx.compose.runtime.Composable + +public class SimpleComposeStep(public val Content: @Composable SimpleComposeStep.() -> Unit) : ComposeStep() { + + @Composable + override fun Compose() { + this.Content() + } +} \ No newline at end of file diff --git a/magellan-compose/src/test/java/com/example/magellan/compose/ExampleUnitTest.kt b/magellan-compose/src/test/java/com/example/magellan/compose/ExampleUnitTest.kt new file mode 100644 index 00000000..9824535a --- /dev/null +++ b/magellan-compose/src/test/java/com/example/magellan/compose/ExampleUnitTest.kt @@ -0,0 +1,18 @@ +package com.example.magellan.compose + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index b1bb9570..486b3cda 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,3 +6,4 @@ include ':magellan-rx2' include ':magellan-sample' include ':magellan-sample-advanced' include ':magellan-support' +include ':magellan-compose' From 0b4bf6616a4e44bf5627493add2e7c3db5c356a7 Mon Sep 17 00:00:00 2001 From: Ryan Moelter Date: Thu, 24 Jun 2021 01:12:42 -0700 Subject: [PATCH 2/6] Try to get beta09 working --- RELEASING.md | 2 +- build.gradle | 5 +- buildSrc/build.gradle | 6 ++- buildSrc/src/main/kotlin/Dependencies.kt | 7 +++ buildSrc/src/main/kotlin/Versions.kt | 13 +++--- gradle.properties | 7 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- magellan-compose/build.gradle | 10 ++-- .../ActivityLifecycleComposeAdapter.kt | 46 +++++++++++++++++++ .../magellan/compose/ComposeInterop.kt | 2 +- magellan-legacy/build.gradle | 8 ++-- magellan-library/build.gradle | 8 ++-- magellan-rx/build.gradle | 8 ++-- magellan-rx2/build.gradle | 8 ++-- magellan-sample-advanced/build.gradle | 5 +- magellan-sample/build.gradle | 26 +++++++++-- .../magellan/sample/FirstJourney.kt | 3 +- .../wealthfront/magellan/sample/IntroStep.kt | 29 ++++++++---- magellan-support/build.gradle | 6 +-- 19 files changed, 149 insertions(+), 52 deletions(-) create mode 100644 magellan-compose/src/main/java/com/example/magellan/compose/ActivityLifecycleComposeAdapter.kt diff --git a/RELEASING.md b/RELEASING.md index cbec0b65..6ef74c54 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -18,4 +18,4 @@ If step 6 or 7 fails, drop the Sonatype repo, fix the problem, commit, and start 1. Set up [signatory credentials](https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signatory_credentials), or temporarily comment out the `signing` block in `gradle/gradle-mvn-push.gradle`. 2. Run `./gradlew publishToMavenLocal`. 3. In the other project, add `mavenLocal()` as a repository (likely in `allProjects.repositories` of the root `build.gradle` file). -4. Update `com.wealthfront:magellan:X.Y.Z` to `com.wealthfront:magellan-library:SNAPSHOT_VERSION`, where `SNAPSHOT_VERSION` is the `VERSION_NAME` defined in this project's `./gradle.properties`. +4. Update `com.wealthfront:magellan-library:X.Y.Z` to `com.wealthfront:magellan-library:SNAPSHOT_VERSION`, where `SNAPSHOT_VERSION` is the `VERSION_NAME` defined in this project's `./gradle.properties`. diff --git a/build.gradle b/build.gradle index b43aa426..fbd35e50 100644 --- a/build.gradle +++ b/build.gradle @@ -2,12 +2,13 @@ buildscript { repositories { - jcenter() - mavenCentral() google() + mavenCentral() + jcenter() } dependencies { classpath(Dependencies.kotlinGradle) + classpath(Dependencies.androidGradle) classpath(Dependencies.kotlinterGradle) classpath(Dependencies.kotlinAllOpen) } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 44ddf111..520ae546 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.jetbrains.kotlin.jvm' version '1.4.30' + id 'org.jetbrains.kotlin.jvm' version '1.5.10' } repositories { @@ -9,18 +9,20 @@ repositories { } dependencies { - implementation "com.android.tools.build:gradle:7.0.0-alpha15" + implementation 'com.android.tools.build:gradle:7.0.0-beta04' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } compileKotlin { kotlinOptions { jvmTarget = "1.8" + useIR = true } } compileTestKotlin { kotlinOptions { jvmTarget = "1.8" + useIR = true } } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 5917646b..284470a6 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -1,3 +1,4 @@ +import Versions.androidGradleVersion import Versions.archVersion import Versions.butterKnifeVersion import Versions.composeVersion @@ -31,12 +32,14 @@ import Versions.uiAutomatorVersion object Dependencies { const val kotlinStdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" + const val kotlinReflect = "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" const val appCompat = "androidx.appcompat:appcompat:$supportLibVersion" const val lifecycle = "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" const val kotlinGradle = "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" const val kotlinterGradle = "org.jmailen.gradle:kotlinter-gradle:$kotlinterVersion" const val kotlinAllOpen = "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion" + const val androidGradle = "com.android.tools.build:gradle:$androidGradleVersion" const val material = "com.google.android.material:material:$materialVersion" const val junit = "junit:junit:$junitVersion" @@ -53,9 +56,13 @@ object Dependencies { const val coroutinesAndroid = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" const val coroutinesTest = "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion" + const val composeCompiler = "androidx.compose.compiler:compiler:$composeVersion" const val composeUi = "androidx.compose.ui:ui:$composeVersion" + const val composeUiUtil = "androidx.compose.ui:ui-util:$composeVersion" const val composeUiTooling = "androidx.compose.ui:ui-tooling:$composeVersion" const val composeFoundation = "androidx.compose.foundation:foundation:$composeVersion" + const val composeFoundationLayout = "androidx.compose.foundation:foundation-layout:$composeVersion" + const val composeRuntime = "androidx.compose.runtime:runtime:$composeVersion" const val composeMaterial = "androidx.compose.material:material:$composeVersion" const val glide = "com.github.bumptech.glide:glide:$glideVersion" diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index c811d628..f9de2b70 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -3,10 +3,12 @@ object Versions { const val minSdkVersion = 21 const val targetSdkVersion = 30 - const val kotlinVersion = "1.4.30" - const val kotlinterVersion = "3.4.0" - const val buildToolsVersion = "30.0.2" - const val detektVersion = "1.5.1" + const val kotlinVersion = "1.5.10" + const val androidGradleVersion = "7.0.0-beta04" + const val coroutinesVersion = "1.5.0" + const val kotlinterVersion = "3.4.5" + const val buildToolsVersion = "30.0.3" + const val detektVersion = "1.17.1" const val supportLibVersion = "1.1.0" const val robolectricVersion = "4.3.1" const val archVersion = "2.1.0" @@ -24,8 +26,7 @@ object Versions { const val okhttpVersion = "4.4.0" const val javaInjectVersion = "1" const val materialVersion = "1.1.0" - const val coroutinesVersion = "1.4.3" - const val composeVersion = "1.0.0-beta01" + const val composeVersion = "1.0.0-beta09" const val testCoreVersion = "1.2.0" const val junitVersion = "4.13" diff --git a/gradle.properties b/gradle.properties index b628faa5..9ddda3cb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.wealthfront -VERSION_NAME=2.1.1 +VERSION_NAME=2.2.0-SNAPSHOT POM_DESCRIPTION=The simplest navigation library for Android @@ -20,3 +20,8 @@ SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots/ android.useAndroidX=true android.enableJetifier=true + +# Turn on parallel compilation, caching and on-demand configuration +org.gradle.configureondemand=true +org.gradle.caching=true +org.gradle.parallel=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ccbe0a4a..34576f11 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip diff --git a/magellan-compose/build.gradle b/magellan-compose/build.gradle index 873a5ac7..2473641f 100644 --- a/magellan-compose/build.gradle +++ b/magellan-compose/build.gradle @@ -5,16 +5,14 @@ group = GROUP version = VERSION_NAME android { - compileSdkVersion Versions.compileSdkVersion - buildToolsVersion Versions.buildToolsVersion + compileSdk Versions.compileSdkVersion + buildToolsVersion = Versions.buildToolsVersion resourcePrefix 'magellan_' defaultConfig { minSdkVersion Versions.minSdkVersion targetSdkVersion Versions.targetSdkVersion - versionCode 1 - versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -45,6 +43,7 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { } kotlinOptions.allWarningsAsErrors = true kotlinOptions.jvmTarget = "1.8" + kotlinOptions.useIR = true } dependencies { @@ -52,12 +51,15 @@ dependencies { implementation Dependencies.appCompat implementation Dependencies.kotlinStdLib + implementation Dependencies.kotlinReflect implementation Dependencies.inject implementation Dependencies.coroutines implementation Dependencies.coroutinesAndroid implementation Dependencies.composeUi implementation Dependencies.composeUiTooling implementation Dependencies.composeFoundation + implementation 'androidx.activity:activity-compose:1.3.0-beta02' + implementation Dependencies.lifecycle testImplementation Dependencies.testCore testImplementation Dependencies.junit diff --git a/magellan-compose/src/main/java/com/example/magellan/compose/ActivityLifecycleComposeAdapter.kt b/magellan-compose/src/main/java/com/example/magellan/compose/ActivityLifecycleComposeAdapter.kt new file mode 100644 index 00000000..61ceaf32 --- /dev/null +++ b/magellan-compose/src/main/java/com/example/magellan/compose/ActivityLifecycleComposeAdapter.kt @@ -0,0 +1,46 @@ +package com.example.magellan.compose + +import android.app.Activity +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.runtime.Composable +import androidx.lifecycle.DefaultLifecycleObserver +import com.wealthfront.magellan.core.Navigable +import com.wealthfront.magellan.lifecycle.LifecycleOwner +import com.wealthfront.magellan.lifecycle.LifecycleState + +public class ActivityLifecycleComposeAdapter( + private val navigable: Navigable<@Composable () -> Unit>, + private val context: Activity +) : DefaultLifecycleObserver { + + override fun onStart(owner: androidx.lifecycle.LifecycleOwner) { + navigable.show(context) + } + + override fun onResume(owner: androidx.lifecycle.LifecycleOwner) { + navigable.resume(context) + } + + override fun onPause(owner: androidx.lifecycle.LifecycleOwner) { + navigable.pause(context) + } + + override fun onStop(owner: androidx.lifecycle.LifecycleOwner) { + navigable.hide(context) + } + + override fun onDestroy(owner: androidx.lifecycle.LifecycleOwner) { + if (context.isFinishing) { + navigable.destroy(context.applicationContext) + } + } +} + +public fun ComponentActivity.setContentNavigable(navigable: Navigable<@Composable () -> Unit>) { + setContent { navigable.view!!() } + if (navigable is LifecycleOwner && navigable.currentState == LifecycleState.Destroyed) { + navigable.create(applicationContext) + } + lifecycle.addObserver(ActivityLifecycleComposeAdapter(navigable, this)) +} diff --git a/magellan-compose/src/main/java/com/example/magellan/compose/ComposeInterop.kt b/magellan-compose/src/main/java/com/example/magellan/compose/ComposeInterop.kt index caa4742b..8243e780 100644 --- a/magellan-compose/src/main/java/com/example/magellan/compose/ComposeInterop.kt +++ b/magellan-compose/src/main/java/com/example/magellan/compose/ComposeInterop.kt @@ -32,7 +32,7 @@ public class ComposeStepWrapper( override val view: View? by lifecycleWithContext { context -> ComposeView(context).apply { - setContent @Composable { composeStep.view!!() } + setContent(content = { composeStep.view!!() }) } } } diff --git a/magellan-legacy/build.gradle b/magellan-legacy/build.gradle index e226ab11..217b8e3f 100644 --- a/magellan-legacy/build.gradle +++ b/magellan-legacy/build.gradle @@ -5,16 +5,14 @@ group = GROUP version = VERSION_NAME android { - compileSdkVersion Versions.compileSdkVersion - buildToolsVersion Versions.buildToolsVersion + compileSdk Versions.compileSdkVersion + buildToolsVersion = Versions.buildToolsVersion resourcePrefix 'magellan_' defaultConfig { minSdkVersion Versions.minSdkVersion targetSdkVersion Versions.targetSdkVersion - versionCode 1 - versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -37,6 +35,7 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { } kotlinOptions.allWarningsAsErrors = true kotlinOptions.jvmTarget = "1.8" + kotlinOptions.useIR = true } dependencies { @@ -44,6 +43,7 @@ dependencies { implementation Dependencies.appCompat implementation Dependencies.kotlinStdLib + implementation Dependencies.kotlinReflect implementation Dependencies.inject implementation Dependencies.coroutines implementation Dependencies.coroutinesAndroid diff --git a/magellan-library/build.gradle b/magellan-library/build.gradle index 50287297..5cddb482 100644 --- a/magellan-library/build.gradle +++ b/magellan-library/build.gradle @@ -5,16 +5,14 @@ group = GROUP version = VERSION_NAME android { - compileSdkVersion Versions.compileSdkVersion - buildToolsVersion Versions.buildToolsVersion + compileSdk Versions.compileSdkVersion + buildToolsVersion = Versions.buildToolsVersion resourcePrefix 'magellan_' defaultConfig { minSdkVersion Versions.minSdkVersion targetSdkVersion Versions.targetSdkVersion - versionCode 1 - versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -49,10 +47,12 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { } kotlinOptions.allWarningsAsErrors = true kotlinOptions.jvmTarget = "1.8" + kotlinOptions.useIR = true } dependencies { implementation Dependencies.kotlinStdLib + implementation Dependencies.kotlinReflect implementation Dependencies.appCompat implementation Dependencies.lifecycle implementation Dependencies.inject diff --git a/magellan-rx/build.gradle b/magellan-rx/build.gradle index 518aff8f..23292af7 100644 --- a/magellan-rx/build.gradle +++ b/magellan-rx/build.gradle @@ -5,14 +5,12 @@ group = GROUP version = VERSION_NAME android { - compileSdkVersion Versions.compileSdkVersion - buildToolsVersion Versions.buildToolsVersion + compileSdk Versions.compileSdkVersion + buildToolsVersion = Versions.buildToolsVersion defaultConfig { minSdkVersion Versions.minSdkVersion targetSdkVersion Versions.targetSdkVersion - versionCode 1 - versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -35,6 +33,7 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { } kotlinOptions.allWarningsAsErrors = true kotlinOptions.jvmTarget = "1.8" + kotlinOptions.useIR = true } dependencies { @@ -43,6 +42,7 @@ dependencies { implementation Dependencies.rxjava implementation Dependencies.kotlinStdLib + implementation Dependencies.kotlinReflect implementation Dependencies.inject testImplementation Dependencies.junit diff --git a/magellan-rx2/build.gradle b/magellan-rx2/build.gradle index b8eabac6..979c42f7 100644 --- a/magellan-rx2/build.gradle +++ b/magellan-rx2/build.gradle @@ -5,14 +5,12 @@ group = GROUP version = VERSION_NAME android { - compileSdkVersion Versions.compileSdkVersion - buildToolsVersion Versions.buildToolsVersion + compileSdk Versions.compileSdkVersion + buildToolsVersion = Versions.buildToolsVersion defaultConfig { minSdkVersion Versions.minSdkVersion targetSdkVersion Versions.targetSdkVersion - versionCode 1 - versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -35,6 +33,7 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { } kotlinOptions.allWarningsAsErrors = true kotlinOptions.jvmTarget = "1.8" + kotlinOptions.useIR = true } dependencies { @@ -42,6 +41,7 @@ dependencies { implementation project(':magellan-library') implementation Dependencies.kotlinStdLib + implementation Dependencies.kotlinReflect implementation Dependencies.rxjava2 implementation Dependencies.inject diff --git a/magellan-sample-advanced/build.gradle b/magellan-sample-advanced/build.gradle index 8ebb58e9..6c89f5ce 100644 --- a/magellan-sample-advanced/build.gradle +++ b/magellan-sample-advanced/build.gradle @@ -3,8 +3,8 @@ apply plugin: 'kotlin-android' apply plugin: "org.jetbrains.kotlin.kapt" android { - compileSdkVersion Versions.compileSdkVersion - buildToolsVersion Versions.buildToolsVersion + compileSdk Versions.compileSdkVersion + buildToolsVersion = Versions.buildToolsVersion defaultConfig { applicationId "com.wealthfront.magellan.sample" @@ -32,6 +32,7 @@ android { kotlinOptions { jvmTarget = "1.8" + useIR = true } packagingOptions { diff --git a/magellan-sample/build.gradle b/magellan-sample/build.gradle index 794015f1..ac108e68 100644 --- a/magellan-sample/build.gradle +++ b/magellan-sample/build.gradle @@ -3,8 +3,8 @@ apply plugin: 'kotlin-android' apply plugin: "org.jetbrains.kotlin.kapt" android { - compileSdkVersion Versions.compileSdkVersion - buildToolsVersion Versions.buildToolsVersion + compileSdk Versions.compileSdkVersion + buildToolsVersion = Versions.buildToolsVersion defaultConfig { applicationId "com.wealthfront.magellan.sample" @@ -21,7 +21,12 @@ android { } buildFeatures { - viewBinding = true + viewBinding true + compose true + } + + composeOptions { + kotlinCompilerExtensionVersion Versions.composeVersion } lintOptions { @@ -36,13 +41,28 @@ android { } } +tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { + kotlinOptions { + jvmTarget = "1.8" + useIR = true + } +} + dependencies { implementation project(':magellan-library') implementation project(':magellan-legacy') + implementation project(':magellan-compose') implementation Dependencies.appCompat implementation Dependencies.kotlinStdLib + implementation Dependencies.kotlinReflect implementation Dependencies.material + implementation Dependencies.composeUi + implementation Dependencies.composeUiUtil + implementation Dependencies.composeFoundation + implementation Dependencies.composeFoundationLayout + implementation Dependencies.composeMaterial + implementation Dependencies.composeUiTooling implementation Dependencies.dagger kapt Dependencies.daggerCompiler diff --git a/magellan-sample/src/main/java/com/wealthfront/magellan/sample/FirstJourney.kt b/magellan-sample/src/main/java/com/wealthfront/magellan/sample/FirstJourney.kt index 29c6be4a..4d3ef172 100644 --- a/magellan-sample/src/main/java/com/wealthfront/magellan/sample/FirstJourney.kt +++ b/magellan-sample/src/main/java/com/wealthfront/magellan/sample/FirstJourney.kt @@ -1,6 +1,7 @@ package com.wealthfront.magellan.sample import android.content.Context +import com.example.magellan.compose.ComposeStepWrapper import com.wealthfront.magellan.core.Journey import com.wealthfront.magellan.sample.App.Provider.appComponent import com.wealthfront.magellan.sample.databinding.FirstJourneyBinding @@ -14,7 +15,7 @@ class FirstJourney( override fun onCreate(context: Context) { appComponent.inject(this) - navigator.goTo(IntroStep(::goToLearnMore)) + navigator.goTo(ComposeStepWrapper(IntroStep(::goToLearnMore))) } override fun onShow(context: Context, binding: FirstJourneyBinding) { diff --git a/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt b/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt index 118a1144..ad1ff42c 100644 --- a/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt +++ b/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt @@ -1,16 +1,29 @@ package com.wealthfront.magellan.sample -import android.content.Context -import com.wealthfront.magellan.core.Step -import com.wealthfront.magellan.sample.databinding.IntroBinding +import androidx.compose.material.Button +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.Devices +import androidx.compose.ui.tooling.preview.Preview +import com.example.magellan.compose.ComposeStep internal class IntroStep( private val goToLearnMore: () -> Unit -) : Step(IntroBinding::inflate) { +) : ComposeStep() { - override fun onShow(context: Context, binding: IntroBinding) { - binding.learnMore.setOnClickListener { - goToLearnMore() - } + @Composable + override fun Compose() = IntroStepContent(goToLearnMore) +} + +@Composable +internal fun IntroStepContent(goToLearnMore: () -> Unit) { + Button(onClick = goToLearnMore) { + Text("Go to learn more") } } + +@Preview(device = Devices.PIXEL_3, name = "Intro step") +@Composable +internal fun IntroStepPreview() { + IntroStepContent { } +} diff --git a/magellan-support/build.gradle b/magellan-support/build.gradle index ec6627e5..dc108065 100644 --- a/magellan-support/build.gradle +++ b/magellan-support/build.gradle @@ -4,14 +4,12 @@ group = GROUP version = VERSION_NAME android { - compileSdkVersion Versions.compileSdkVersion - buildToolsVersion Versions.buildToolsVersion + compileSdk Versions.compileSdkVersion + buildToolsVersion = Versions.buildToolsVersion defaultConfig { minSdkVersion Versions.minSdkVersion targetSdkVersion Versions.targetSdkVersion - versionCode 1 - versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } From 12de00aefc944149ae6978748f4701fcbcb67726 Mon Sep 17 00:00:00 2001 From: Ryan Moelter Date: Thu, 8 Jul 2021 19:50:47 -0700 Subject: [PATCH 3/6] Try to get beta09 working --- .idea/codeStyles/Project.xml | 19 ++----------------- build.gradle | 2 +- buildSrc/build.gradle | 4 ++-- buildSrc/src/main/kotlin/Dependencies.kt | 2 ++ buildSrc/src/main/kotlin/Versions.kt | 9 +++++---- magellan-compose/build.gradle | 3 ++- .../magellan/compose/ComposeInterop.kt | 2 +- 7 files changed, 15 insertions(+), 26 deletions(-) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 29f8ece1..9339ed08 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -54,17 +54,9 @@ -