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

Brings ViewStarter to the UI update. #620

Merged
merged 21 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5be01a5
View.launchWhenAttached tolerates strange ids
rjrjr Dec 9, 2021
757aa20
Merge pull request #604 from square/ray/more-robust-ensureAttachedScope
rjrjr Dec 9, 2021
5931b4a
Fixes index out of bounds crash when attempting to add characters or …
JsFlo Dec 10, 2021
821c7b6
Merge pull request #605 from JsFlo/joseflores/terminalIndexOutOfBounds
rjrjr Dec 10, 2021
e50052d
Adds (failing) DecorativeViewFactory double update test
rjrjr Dec 8, 2021
b93a522
Replaces *.initializeView with *.viewStarter
rjrjr Dec 9, 2021
df925e5
Merge pull request #602 from square/ray/initializeView-is-a-landmine
rjrjr Dec 10, 2021
aeed829
End CHANGELOG.md
rjrjr Dec 10, 2021
5cd4ba2
Merge pull request #607 from square/ray/no-more-changelog
rjrjr Dec 10, 2021
d87bef1
Releasing v1.3.0
rjrjr Dec 10, 2021
085e097
608: Update TypedWorker kdoc
steve-the-edwards Dec 13, 2021
9011f80
Merge pull request #609 from square/sedwards/608-typed-worker-compare…
steve-the-edwards Dec 13, 2021
42b6998
Use Gradle 7.3.2. Log4shell mitigation.
autonomousapps Dec 16, 2021
7c3bdb6
Merge pull request #613 from autonomousapps/patch-1
rjrjr Dec 16, 2021
a80f9a0
Fixes version name after 1.3.0 release, forgot to bump it.
rjrjr Jan 4, 2022
4844ad8
Moves us to s01.oss.sonatype.org
rjrjr Jan 4, 2022
588db3b
Upgrade the compile SDK to 31.
vRallev Jan 5, 2022
a88141c
Merge pull request #617 from square/ralf/compile-sdk
rjrjr Jan 5, 2022
e85d260
Merge pull request #616 from square/ray/sonatype-update
rjrjr Jan 5, 2022
a691e8e
Merge remote-tracking branch 'origin/main' into ray/ui-update
rjrjr Jan 5, 2022
f0dce22
Brings ViewStarter to the UI update.
rjrjr Jan 5, 2022
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
2 changes: 1 addition & 1 deletion .buildscript/configure-android-defaults.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
android {
compileSdkVersion Versions.targetSdk
compileSdkVersion Versions.compileSdk

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
4 changes: 4 additions & 0 deletions .buildscript/configure-maven-publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ apply plugin: 'com.vanniktech.maven.publish'

group = GROUP
version = VERSION_NAME

mavenPublish {
sonatypeHost = "S01"
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Change Log
==========

> This file is no longer updated, please visit [Releases](https://github.com/square/workflow-kotlin/releases) instead.

## Version 1.2.0

_2021-11-10_
Expand Down
25 changes: 11 additions & 14 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
## Production Releases

---
1. Merge an update of [the change log](CHANGELOG.md) with the changes since the last release.

1. Make sure you're on the `main` branch (or fix branch, e.g. `v0.1-fixes`).

1. Confirm that the kotlin build is green before committing any changes
Expand All @@ -23,14 +21,13 @@

1. Upload the kotlin artifacts:
```bash
./gradlew clean build && ./gradlew uploadArchives --no-parallel
./gradlew clean build && ./gradlew publish --no-parallel
```

Disabling parallelism and daemon sharing is required by the vanniktech maven publish plugin.
Without those, the artifacts will be split across multiple (invalid) staging repositories.
(Note that `uploadArchives` is deprecated in favor of `publish`, but `publish` makes bad artifacts.)

1. Close and release the staging repository at https://oss.sonatype.org/#stagingRepositories.
1. Close and release the staging repository at https://s01.oss.sonatype.org/#stagingRepositories.

1. Bump the version
- **Kotlin:** Update the `VERSION_NAME` property in `gradle.properties` to the new
Expand All @@ -51,10 +48,11 @@
1. Create the release on GitHub:
1. Go to the [Releases](https://github.com/square/workflow-kotlin/releases) page for the GitHub
project.
1. Click "Draft a new release".
1. Click _Draft a new release_.
1. Enter the tag name you just pushed.
1. Title the release with the same name as the tag.
1. Copy & paste the changelog entry for this release into the description.
1. Click _Auto-generate release notes_.
- Edit the generated notes if you feel the need.
- See [this page](https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes) if you have an itch to customize how our notes are generated.
1. If this is a pre-release version, check the pre-release box.
1. Hit "Publish release".

Expand Down Expand Up @@ -112,12 +110,11 @@ To build and install the current version to your local Maven repository (`~/.m2`

#### Configuration

In order to deploy artifacts to a Maven repository, you'll need to set 4 properties in your private
Gradle properties file (`~/.gradle/gradle.properties`):
In order to deploy artifacts to `s01.oss.sonatype.org`, you'll need to provide
your credentials via these two properties in your private Gradle properties
file(`~/.gradle/gradle.properties`).

```
RELEASE_REPOSITORY_URL=<url of release repository>
SNAPSHOT_REPOSITORY_URL=<url of snapshot repository
mavenCentralUsername=<username>
mavenCentralPassword=<password>
```
Expand All @@ -128,8 +125,8 @@ Double-check that `gradle.properties` correctly contains the `-SNAPSHOT` suffix,
snapshot artifacts to Sonatype just like you would for a production release:

```bash
./gradlew clean build && ./gradlew uploadArchives --no-parallel
./gradlew clean build && ./gradlew publish --no-parallel
```

You can verify the artifacts are available by visiting
https://oss.sonatype.org/content/repositories/snapshots/com/squareup/workflow/.
https://s01.oss.sonatype.org/content/repositories/snapshots/com/squareup/workflow1/.
3 changes: 2 additions & 1 deletion buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.util.Locale.US
import kotlin.reflect.full.declaredMembers

object Versions {
const val compileSdk = 31
const val targetSdk = 30
}

Expand Down Expand Up @@ -109,7 +110,7 @@ object Dependencies {
const val generator = "org.openjdk.jmh:jmh-generator-annprocess:1.32"
}

const val mavenPublish = "com.vanniktech:gradle-maven-publish-plugin:0.16.0"
const val mavenPublish = "com.vanniktech:gradle-maven-publish-plugin:0.18.0"
const val ktlint = "org.jlleitschuh.gradle:ktlint-gradle:10.1.0"
const val lanterna = "com.googlecode.lanterna:lanterna:3.1.1"
const val okio = "com.squareup.okio:okio:2.10.0"
Expand Down
12 changes: 7 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ android.useAndroidX=true
systemProp.org.gradle.internal.publish.checksums.insecure=true

GROUP=com.squareup.workflow1
VERSION_NAME=1.3.0-SNAPSHOT
VERSION_NAME=1.4.0-SNAPSHOT

POM_DESCRIPTION=Reactive workflows
POM_DESCRIPTION=Square Workflow

POM_URL=https://github.com/square/workflow/
POM_SCM_URL=https://github.com/square/workflow/
POM_SCM_CONNECTION=scm:git:git://github.com/square/workflow.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/square/workflow.git

POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_LICENSE_NAME=The Apache Software License, Version 2.0
POM_LICENSE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENSE_DIST=repo

POM_DEVELOPER_ID=square
POM_DEVELOPER_NAME=Square, Inc.
POM_DEVELOPER_URL=https://github.com/square/
SONATYPE_STAGING_PROFILE=com.squareup
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Component(context: AppCompatActivity) {
@OptIn(ExperimentalTime::class)
val clock = Monotonic

@Suppress("DEPRECATION")
val vibrator = context.getSystemService(VIBRATOR_SERVICE) as Vibrator

val boardLoader = BoardLoader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class EditTextWorkflow : StatefulWorkflow<EditTextProps, EditTextState, String,
override fun initialState(
props: EditTextProps,
snapshot: Snapshot?
) = EditTextState(props.text.length)
) = EditTextState(cursorPosition = props.text.length)

override fun onPropsChanged(
old: EditTextProps,
Expand All @@ -40,7 +40,7 @@ class EditTextWorkflow : StatefulWorkflow<EditTextProps, EditTextState, String,
): EditTextState {
return if (old.text != new.text) {
// Clamp the cursor position to the text length.
state.copy(cursorPosition = state.cursorPosition.coerceIn(0..new.text.length))
state.copy(cursorPosition = state.cursorPosition.coerceIn(new.text))
} else state
}

Expand Down Expand Up @@ -68,18 +68,19 @@ class EditTextWorkflow : StatefulWorkflow<EditTextProps, EditTextState, String,
) = action {
when (key.keyType) {
Character -> {
state = moveCursor(props, state, 1)
props.text.insertCharAt(state.cursorPosition, key.character!!)
val newText = props.text.insertCharAt(state.cursorPosition, key.character!!)
setOutput(newText)
state = moveCursor(newText, state, 1)
}

Backspace -> {
if (props.text.isNotEmpty()) {
state = moveCursor(props, state, -1)
props.text.removeRange(state.cursorPosition - 1, state.cursorPosition)
if (props.text.isNotEmpty() && state.cursorPosition > 0) {
val newText = props.text.removeRange(state.cursorPosition - 1, state.cursorPosition)
setOutput(newText)
state = moveCursor(newText, state, -1)
}
}
ArrowLeft -> state = moveCursor(props, state, -1)
ArrowRight -> state = moveCursor(props, state, 1)
ArrowLeft -> state = moveCursor(props.text, state, -1)
ArrowRight -> state = moveCursor(props.text, state, 1)
else -> {
// Nothing to do.
}
Expand All @@ -88,13 +89,15 @@ class EditTextWorkflow : StatefulWorkflow<EditTextProps, EditTextState, String,
}

private fun moveCursor(
props: EditTextProps,
text: String,
state: EditTextState,
delta: Int
): EditTextState =
state.copy(cursorPosition = (state.cursorPosition + delta).coerceIn(0..props.text.length + 1))
state.copy(cursorPosition = (state.cursorPosition + delta).coerceIn(text))

private fun String.insertCharAt(
index: Int,
char: Char
): String = substring(0, index) + char + substring(index, length)

private fun Int.coerceIn(text: String): Int = coerceIn(0..text.length)
2 changes: 1 addition & 1 deletion samples/tutorial/tutorial-1-complete/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
applicationId "com.squareup.workflow.tutorial"
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorial/tutorial-2-complete/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
applicationId "workflow.tutorial"
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorial/tutorial-3-complete/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
applicationId "workflow.tutorial"
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorial/tutorial-4-complete/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
applicationId "workflow.tutorial"
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorial/tutorial-base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
applicationId "workflow.tutorial"
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorial/tutorial-final/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
applicationId "workflow.tutorial"
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorial/tutorial-views/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
minSdkVersion 21
Expand Down
18 changes: 12 additions & 6 deletions workflow-core/src/main/java/com/squareup/workflow1/Worker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,16 @@ public interface Worker<out OutputT> {
*
* At the end of every render pass, the set of [Worker]s that were requested by the workflow are
* compared to the set from the last render pass using this method. Workers are compared by their
* _declared_ type. Equivalent workers are allowed to keep running. New workers are started ([run]
* is called and the returned [Flow] is collected). Old workers are cancelled by cancelling their
* collecting coroutines. Workers for which [doesSameWorkAs] returns false will also be restarted.
* _declared_ [KType] - including generics. Equivalent workers are allowed to keep running.
* New workers are started ([run] is called and the returned [Flow] is collected). Old workers are
* cancelled by cancelling their collecting coroutines. Workers for which [doesSameWorkAs] returns
* false will also be restarted.
*
* Implementations of this method should not be based on object identity. For example, a [Worker]
* that performs a network request might check that two workers are requests to the same endpoint
* and have the same request data.
* Implementations of this method should not be based on object identity. Nor do they need to be
* based on anything including in the [KType] - such as generics - as those will already be
* compared by the Workflow Runtime, see [WorkerWorkflow].
* For example, a [Worker] that performs a network request might check that two workers are
* requests to the same endpoint and have the same request data.
*
* Most implementations of this method should compare constructor parameters.
*
Expand Down Expand Up @@ -314,6 +317,9 @@ public fun <T, R> Worker<T>.transform(
/**
* A generic [Worker] implementation that defines equivalent workers as those having equivalent
* [outputType]s. This is used by all the [Worker] builder functions.
*
* Note: We do not override the [doesSameWorkAs] definition here because the [outputType] [KType]
* is already compared as part of the [KType] of the class itself in the Workflow runtime.
*/
@PublishedApi
internal class TypedWorker<OutputT>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.squareup.workflow1.ui.WorkflowViewStub
import com.squareup.workflow1.ui.getFactoryForRendering
import com.squareup.workflow1.ui.getShowRendering
import com.squareup.workflow1.ui.showRendering
import com.squareup.workflow1.ui.start
import kotlin.reflect.KClass

/**
Expand Down Expand Up @@ -186,6 +187,8 @@ private fun <R : Any> ViewFactory<R>.asComposeViewFactory() =
// we don't have access to that.
originalFactory.buildView(rendering, viewEnvironment, context, container = null)
.also { view ->
view.start()

// Mirrors the check done in ViewRegistry.buildView.
checkNotNull(view.getShowRendering<Any>()) {
"View.bindShowRendering should have been called for $view, typically by the " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.squareup.workflow1.ui.buildView
import com.squareup.workflow1.ui.modal.ModalViewContainer.Companion.binding
import com.squareup.workflow1.ui.onBackPressedDispatcherOwnerOrNull
import com.squareup.workflow1.ui.showRendering
import com.squareup.workflow1.ui.start
import kotlin.reflect.KClass

/**
Expand Down Expand Up @@ -70,6 +71,7 @@ public open class ModalViewContainer @JvmOverloads constructor(
container = this
)
.apply {
start()
// If the modal's root view has no backPressedHandler, add a no-op one to
// ensure that the `onBackPressed` call below will not leak up to handlers
// that should be blocked by this modal session.
Expand Down
Loading