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

Fix tutorial fileTemplates #1158

Merged
merged 1 commit into from
Jan 19, 2024
Merged

Conversation

rjrjr
Copy link
Contributor

@rjrjr rjrjr commented Jan 19, 2024

Our templates were out of date, and our install.sh script doesn't work any more.
Replaced with an IDE-produced zip file that the IDE is willing to import.

Replaces Layout Runner (ViewBinding) with Android Screen (ViewBinding):

package ${PACKAGE_NAME}

import com.squareup.workflow1.ui.AndroidScreen
import com.squareup.workflow1.ui.ScreenViewFactory
import com.squareup.workflow1.ui.ScreenViewRunner
import com.squareup.workflow1.ui.ViewEnvironment
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi

@OptIn(WorkflowUiExperimentalApi::class)
data class $Name(
  // TODO: add properties needed to update $VIEW_BINDING_TYPE
) : AndroidScreen<$Name> {

  override val viewFactory =
    ScreenViewFactory.fromViewBinding($VIEW_BINDING_TYPE::inflate, ::${Name}Runner)
}

@OptIn(WorkflowUiExperimentalApi::class)
private class ${Name}Runner(
  private val viewBinding: $VIEW_BINDING_TYPE
) : ScreenViewRunner<$Name> {

  override fun showRendering(
    rendering: $Name,
    environment: ViewEnvironment
  ) {
    TODO("Update viewBinding from rendering")
  }
}

@rjrjr rjrjr requested review from zach-klippenstein and a team as code owners January 19, 2024 01:09
@rjrjr rjrjr force-pushed the ray/tutorial-fileTemplates branch 2 times, most recently from ff167ae to faee0d7 Compare January 19, 2024 01:11
@rjrjr rjrjr changed the title Fix fileTemplates Fix tutorial fileTemplates Jan 19, 2024
@rjrjr rjrjr force-pushed the ray/tutorial-fileTemplates branch 6 times, most recently from 3056b82 to 6cb764b Compare January 19, 2024 01:22
Our templates were out of date, and our `install.sh` script doesn't work any more.
Replaced with an IDE-produced zip file that the IDE is willing to import.

Replaces `Layout Runner (ViewBinding)` with `Android Screen (ViewBinding)`:

```kotlin
package ${PACKAGE_NAME}

import com.squareup.workflow1.ui.AndroidScreen
import com.squareup.workflow1.ui.ScreenViewFactory
import com.squareup.workflow1.ui.ScreenViewRunner
import com.squareup.workflow1.ui.ViewEnvironment
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi

@OptIn(WorkflowUiExperimentalApi::class)
data class $Name(
  // TODO: add properties needed to update $VIEW_BINDING_TYPE
) : AndroidScreen<$Name> {

  override val viewFactory =
    ScreenViewFactory.fromViewBinding($VIEW_BINDING_TYPE::inflate, ::${Name}Runner)
}

@OptIn(WorkflowUiExperimentalApi::class)
private class ${Name}Runner(
  private val viewBinding: $VIEW_BINDING_TYPE
) : ScreenViewRunner<$Name> {

  override fun showRendering(
    rendering: $Name,
    environment: ViewEnvironment
  ) {
    TODO("Update viewBinding from rendering")
  }
}
```
@rjrjr rjrjr force-pushed the ray/tutorial-fileTemplates branch from 6cb764b to 207762a Compare January 19, 2024 01:28
@ijwhelan
Copy link
Collaborator

Any reason not to encourage usage of the other flavor of fromViewBinding() that allows for a trailing lambda containing the ScreenViewRunner's logic instead?

@rjrjr
Copy link
Contributor Author

rjrjr commented Jan 19, 2024

Any reason not to encourage usage of the other flavor of fromViewBinding() that allows for a trailing lambda containing the ScreenViewRunner's logic instead?

Good catch. I actually considered that but backed away from it, because that makes it so easy to accidentally capture the first rendering instead of using the one passed to the lambda. I figure for a tutorial it's good to have all the moving parts visible, even at the expense of more boilerplate. And I really doubt these templates will get much use outside of the tutorial.

Base automatically changed from ray/tutorial-final-navigation-catchup to ray/tutorial-update January 19, 2024 21:11
@rjrjr rjrjr merged commit 8c817e3 into ray/tutorial-update Jan 19, 2024
3 checks passed
@rjrjr rjrjr deleted the ray/tutorial-fileTemplates branch January 19, 2024 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants