-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spike compose support #177
base: displayable-generic
Are you sure you want to change the base?
Changes from all commits
87efc5a
0b4bf66
12de00a
031a81b
7ed940a
f1ebf8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' version '1.3.72' | ||
id 'org.jetbrains.kotlin.jvm' version '1.4.32' | ||
} | ||
|
||
repositories { | ||
|
@@ -9,18 +9,22 @@ repositories { | |
} | ||
|
||
dependencies { | ||
implementation "com.android.tools.build:gradle:4.1.1" | ||
implementation 'com.android.tools.build:gradle:7.0.0-beta05' | ||
// See https://issuetracker.google.com/issues/176079157#comment11 | ||
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10" | ||
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Figuring this out took literally TWO AND A HALF MONTHS. Everything else worked from the start. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's pretty annoying. |
||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | ||
} | ||
|
||
compileKotlin { | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
useIR = true | ||
} | ||
} | ||
|
||
compileTestKotlin { | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
useIR = true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
|
||
group = GROUP | ||
version = VERSION_NAME | ||
|
||
android { | ||
compileSdk Versions.compileSdkVersion | ||
buildToolsVersion = Versions.buildToolsVersion | ||
|
||
resourcePrefix 'magellan_' | ||
|
||
defaultConfig { | ||
minSdkVersion Versions.minSdkVersion | ||
targetSdkVersion Versions.targetSdkVersion | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildFeatures { | ||
compose true | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
useIR = true | ||
} | ||
|
||
composeOptions { | ||
kotlinCompilerExtensionVersion Versions.composeVersion | ||
} | ||
|
||
compileOptions { | ||
setSourceCompatibility(JavaVersion.VERSION_1_8) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might need to bump this to Java 11 for compatibility with arctic fox. |
||
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" | ||
kotlinOptions.useIR = true | ||
} | ||
|
||
dependencies { | ||
implementation project(':magellan-library') | ||
|
||
implementation Dependencies.appCompat | ||
implementation Dependencies.kotlinStdLib | ||
implementation Dependencies.kotlinReflect | ||
implementation Dependencies.inject | ||
implementation Dependencies.coroutines | ||
implementation Dependencies.coroutinesAndroid | ||
implementation Dependencies.composeUi | ||
implementation Dependencies.composeUiUtil | ||
implementation Dependencies.composeUiTooling | ||
implementation Dependencies.composeFoundation | ||
implementation Dependencies.activityCompose | ||
implementation Dependencies.lifecycle | ||
|
||
testImplementation Dependencies.testCore | ||
testImplementation Dependencies.junit | ||
testImplementation Dependencies.truth | ||
testImplementation Dependencies.mockito | ||
testImplementation Dependencies.robolectric | ||
} | ||
|
||
apply from: rootProject.file('gradle/gradle-mvn-push.gradle') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
POM_ARTIFACT_ID=magellan-compose | ||
POM_NAME=Magellan Compose | ||
POM_DESCRIPTION=Compose support for Magellan | ||
POM_PACKAGING=aar |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.magellan.compose" | ||
> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 | ||
|
||
private typealias AndroidLifecycleOwner = androidx.lifecycle.LifecycleOwner | ||
|
||
public class ActivityLifecycleComposeAdapter( | ||
private val navigable: Navigable<@Composable () -> Unit>, | ||
private val context: Activity | ||
) : DefaultLifecycleObserver { | ||
|
||
override fun onStart(owner: AndroidLifecycleOwner) { | ||
navigable.show(context) | ||
} | ||
|
||
override fun onResume(owner: AndroidLifecycleOwner) { | ||
navigable.resume(context) | ||
} | ||
|
||
override fun onPause(owner: AndroidLifecycleOwner) { | ||
navigable.pause(context) | ||
} | ||
|
||
override fun onStop(owner: AndroidLifecycleOwner) { | ||
navigable.hide(context) | ||
} | ||
|
||
override fun onDestroy(owner: AndroidLifecycleOwner) { | ||
if (context.isFinishing) { | ||
navigable.destroy(context.applicationContext) | ||
} | ||
} | ||
} | ||
|
||
public fun ComponentActivity.setContentNavigable(navigable: Navigable<@Composable () -> Unit>) { | ||
if (navigable is LifecycleOwner && navigable.currentState == LifecycleState.Destroyed) { | ||
navigable.create(applicationContext) | ||
} | ||
lifecycle.addObserver(ActivityLifecycleComposeAdapter(navigable, this)) | ||
setContent { navigable.view!!() } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Since AS arctic fox has been released, we can bump this to the stable version. Same with compose 🥳