Skip to content

Commit

Permalink
Merge pull request #3 from noties/F/adapt-ui
Browse files Browse the repository at this point in the history
v5.0
  • Loading branch information
noties authored Jul 16, 2023
2 parents 6fb0fc8 + f3b4394 commit 7a440d5
Show file tree
Hide file tree
Showing 374 changed files with 37,814 additions and 492 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Build

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: set up JDK
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build with Gradle
run: ./gradlew check --stacktrace
17 changes: 17 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Pull request checks

on: pull_request

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: set up JDK
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build with Gradle
run: ./gradlew check --stacktrace
61 changes: 61 additions & 0 deletions .run/sample.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="sample" type="AndroidRunConfigurationType" factoryName="Android App" activateToolWindowBeforeRun="false">
<module name="AdaptParent.sample.main" />
<option name="DEPLOY" value="true" />
<option name="DEPLOY_APK_FROM_BUNDLE" value="false" />
<option name="DEPLOY_AS_INSTANT" value="false" />
<option name="ARTIFACT_NAME" value="" />
<option name="PM_INSTALL_OPTIONS" value="" />
<option name="ALL_USERS" value="false" />
<option name="ALWAYS_INSTALL_WITH_PM" value="false" />
<option name="CLEAR_APP_STORAGE" value="false" />
<option name="DYNAMIC_FEATURES_DISABLED_LIST" value="" />
<option name="ACTIVITY_EXTRA_FLAGS" value="--es aid &quot;20230715105856&quot;" />
<option name="MODE" value="default_activity" />
<option name="CLEAR_LOGCAT" value="false" />
<option name="SHOW_LOGCAT_AUTOMATICALLY" value="false" />
<option name="INSPECTION_WITHOUT_ACTIVITY_RESTART" value="false" />
<option name="TARGET_SELECTION_MODE" value="DEVICE_AND_SNAPSHOT_COMBO_BOX" />
<option name="SELECTED_CLOUD_MATRIX_CONFIGURATION_ID" value="-1" />
<option name="SELECTED_CLOUD_MATRIX_PROJECT_ID" value="" />
<option name="DEBUGGER_TYPE" value="Auto" />
<Auto>
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
<option name="SHOW_STATIC_VARS" value="true" />
<option name="WORKING_DIR" value="" />
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
</Auto>
<Hybrid>
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
<option name="SHOW_STATIC_VARS" value="true" />
<option name="WORKING_DIR" value="" />
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
</Hybrid>
<Java />
<Native>
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
<option name="SHOW_STATIC_VARS" value="true" />
<option name="WORKING_DIR" value="" />
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
</Native>
<Profilers>
<option name="ADVANCED_PROFILING_ENABLED" value="false" />
<option name="STARTUP_PROFILING_ENABLED" value="false" />
<option name="STARTUP_CPU_PROFILING_ENABLED" value="false" />
<option name="STARTUP_CPU_PROFILING_CONFIGURATION_NAME" value="Callstack Sample" />
<option name="STARTUP_NATIVE_MEMORY_PROFILING_ENABLED" value="false" />
<option name="NATIVE_MEMORY_SAMPLE_RATE_BYTES" value="2048" />
<option name="PROFILING_MODE" value="NOT_SET" />
</Profilers>
<option name="DEEP_LINK" value="" />
<option name="ACTIVITY_CLASS" value="" />
<option name="SEARCH_ACTIVITY_IN_GLOBAL_SCOPE" value="false" />
<option name="SKIP_ACTIVITY_VALIDATION" value="false" />
<method v="2">
<option name="Android.Gradle.BeforeRunTask" enabled="true" />
</method>
</configuration>
</component>
118 changes: 118 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,123 @@
# Changelog

# 5.0.0
### Changed
* `Text`: `.textFont` => `.textTypeface`

#### Shape
`Shape` has changed API. Right now all shapes are named following basic pattern - `RectangleShape`,
`OvalShape`, etc. And previous `Rectangle`, `Oval` are used in factory building.

Before:
```kotlin
View()
.layoutFill()
.background(Rectangle {
fill(Color.BLACK)
})
.background(ShapeDrawable {
Rectangle {
add(Oval {
fill(Color.RED)
})
}
})
```

After:
```kotlin
View()
.layoutFill()
// now `background` and `foreground` expose function to build Shape with ShapeFactory
.background { /*ShapeFactory.() -> Shape*/
// function defined in `ShapeFactory`
Rectangle()
}
// new factory method in Shape
.background(Shape.builder {
Rectangle {
// no need to call `add`, `Oval` automatically adds OvalShape
Oval()

// still shape is returned and can be referenced
// NB! this `CircleShape` has been added to the parent `RectangleShape`
val circle = Circle()

// If you need to create a shape without adding it - use proper class name:
val notAddedCircle = CircleShape()

// add is still present, shapes can be added manually
add(notAddedCircle.copy())
}
})
.background(ShapeDrawable {
// NB! this `ShapeDrawable` function signature is still the same, so most usages
// should be fine. You might want to remove additional `add` calls as shapes,
// referenced via `ShapeFactory` functions are added automatically
Rectangle {
// it is valid, shape won't be added twice..
add(Oval())
// ..but better to remove `add` all-together
Oval()
}
})
```

The easiest path to migrate to new `Shape` is to explicitly specify proper name
* `Rectangle {}` -&gt; `RectangleShape {}`
* `Oval {}` -&gt; `OvalShape {}`
* etc, for all the shapes

Then, new factory functions can be used, depending on the use-case and should be reviewed manually.
For example, in case of `background` for a `ViewElement`

```diff
View()
.layoutFill()
- .background(Rectangle {
- // shape definition
- })
+ .background {
+ Rectangle {
+ // shape definition
+ }
+ }
```

*Please carefully review* your shape definitions, as most of things won't require a special attention,
but in some cases it might lead to different results, for example:

```kotlin
// before:
val shape = Rectangle {
val base = Oval().fill(Color.RED)
add(base.copy {
fill(Color.YELLOW)
})
add(base.copy {
stroke(Color.GREEN)
})
}

// after `Rectangle` was changed to `RectangleShape`:
val shape = RectangleShape {
// NB! this line, Oval is automatically added to the parent shape
// which in this case, most likely, is not what is needed, change to `OvalShape` instead
val wrongBase = Oval().fill(Color.RED)
val validBase = OvalShape().fill(Color.RED)
add(base.copy {
fill(Color.YELLOW)
})
add(base.copy {
stroke(Color.GREEN)
})
}

// NB! as a rule, if result is stored, most likely, full shape name must be used:
val shape = Oval() // it is valid `Oval` returns shape, but it is already added
val shape = OvalShape() // proper usage
```

# 4.0.0

### Added
Expand Down
4 changes: 4 additions & 0 deletions DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ attempt at creating proper abstraction for re-usable view components across diff
`Padding Margin Item` and `Padding Item` are not the same
* uniqueness of generated viewType combined with reliable generator that can
be proven and does not rely on some randomness of hashcode

# Benefits
* adding background would require modification of existing components, so delegation
* for single file - refactoring, for example cleaning

27 changes: 27 additions & 0 deletions LIVE_TEMPLATES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# Generate a new AdaptUISampleView with preview
Create a new Kotlin file with name for the sample

```
@io.noties.adapt.sample.annotation.AdaptSample(
id = $ID$,
title = "$TITLE$",
description = "$DESCRIPTION$",
tags = ["adapt-ui", $TAGS$]
)
class $SAMPLE_NAME$: io.noties.adapt.sample.samples.adaptui.AdaptUISampleView() {
override fun io.noties.adapt.ui.ViewFactory<io.noties.adapt.ui.LayoutParams>.body() {
$END$
}
}
@io.noties.adapt.sample.util.Preview
@Suppress("ClassName", "unused")
private class Preview__$SAMPLE_NAME$(
context: android.content.Context,
attrs: android.util.AttributeSet?
) : io.noties.adapt.sample.util.PreviewSampleView(context, attrs) {
override val sampleView: io.noties.adapt.sample.SampleView
get() = $SAMPLE_NAME$()
}
```
Loading

0 comments on commit 7a440d5

Please sign in to comment.