-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4a4d94
commit c9f26a2
Showing
16 changed files
with
229 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
POM_ARTIFACT_ID=magellan-compose | ||
POM_NAME=Magellan Compose | ||
POM_DESCRIPTION=Compose support for Magellan | ||
POM_PACKAGING=aar |
25 changes: 25 additions & 0 deletions
25
...llan-compose/src/androidTest/java/com/example/magellan/compose/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.magellan.compose" | ||
> | ||
|
||
</manifest> |
9 changes: 9 additions & 0 deletions
9
magellan-compose/src/main/java/com/example/magellan/compose/ComposeExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.magellan.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.wealthfront.magellan.core.Displayable | ||
|
||
@Composable | ||
public fun Displayable(displayable: Displayable<@Composable () -> Unit>) { | ||
displayable.view!!() | ||
} |
49 changes: 49 additions & 0 deletions
49
magellan-compose/src/main/java/com/example/magellan/compose/ComposeInterop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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<View>, 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<View> { | ||
|
||
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<View> | ||
) : LifecycleAwareComponent(), Navigable<@Composable () -> Unit> { | ||
|
||
public val viewStep: Navigable<View> by lifecycle(viewStep) | ||
|
||
override val view: @Composable () -> Unit = { | ||
Displayable(viewStep) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
magellan-compose/src/main/java/com/example/magellan/compose/ComposeStep.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() | ||
} |
11 changes: 11 additions & 0 deletions
11
magellan-compose/src/main/java/com/example/magellan/compose/SimpleComposeStep.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
magellan-compose/src/test/java/com/example/magellan/compose/ExampleUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters