Skip to content
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

Draft
wants to merge 6 commits into
base: displayable-generic
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

buildscript {
repositories {
jcenter()
mavenCentral()
google()
mavenCentral()
jcenter()
}
dependencies {
classpath(Dependencies.kotlinGradle)
classpath(Dependencies.androidGradle)
classpath(Dependencies.kotlinterGradle)
classpath(Dependencies.kotlinAllOpen)
}
}

plugins {
id 'io.gitlab.arturbosch.detekt' version '1.5.1'
id 'io.gitlab.arturbosch.detekt' version '1.18.0-RC1'
}

allprojects {
Expand Down
8 changes: 6 additions & 2 deletions buildSrc/build.gradle
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 {
Expand All @@ -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'
Copy link
Contributor

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 🥳

// See https://issuetracker.google.com/issues/176079157#comment11
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
Comment on lines +13 to +14
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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
}
}
15 changes: 15 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Versions.activityComposeVersion
import Versions.androidGradleVersion
import Versions.archVersion
import Versions.butterKnifeVersion
import Versions.composeVersion
import Versions.coroutinesVersion
import Versions.daggerVersion
import Versions.espressoVersion
Expand Down Expand Up @@ -30,12 +33,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"
Expand All @@ -52,6 +57,16 @@ 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 activityCompose = "androidx.activity:activity-compose:$activityComposeVersion"

const val glide = "com.github.bumptech.glide:glide:$glideVersion"
const val retrofit = "com.squareup.retrofit2:retrofit:$retrofitVersion"
const val rxjava = "io.reactivex:rxjava:$rxjavaVersion"
Expand Down
15 changes: 9 additions & 6 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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 detektVersion = "1.5.1"
const val kotlinVersion = "1.5.10"
const val androidGradleVersion = "7.0.0-beta05"
const val coroutinesVersion = "1.5.0"
const val kotlinterVersion = "3.4.5"
const val buildToolsVersion = "31.0.0-rc5"
const val detektVersion = "1.17.1"
const val supportLibVersion = "1.1.0"
const val robolectricVersion = "4.3.1"
const val archVersion = "2.1.0"
Expand All @@ -24,7 +26,8 @@ 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-rc02"
const val activityComposeVersion = "1.3.0-rc02"

const val testCoreVersion = "1.2.0"
const val junitVersion = "4.13"
Expand Down
7 changes: 6 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.2-all.zip
1 change: 1 addition & 0 deletions magellan-compose/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
77 changes: 77 additions & 0 deletions magellan-compose/build.gradle
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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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')
4 changes: 4 additions & 0 deletions magellan-compose/gradle.properties
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)
}
}
7 changes: 7 additions & 0 deletions magellan-compose/src/main/AndroidManifest.xml
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!!() }
}
Loading