Skip to content

Commit 20f6026

Browse files
authored
Merge pull request #886 from square/ray/intentional-animation
Improved animation for BackStackContainer, PanelContainer.
2 parents 7d8e885 + 0e5ad4a commit 20f6026

File tree

8 files changed

+165
-0
lines changed

8 files changed

+165
-0
lines changed

kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/panel/PanelContainer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import kotlin.math.min
3939
object PanelContainer : ViewBinding<PanelContainerScreen<*, *>>
4040
by ModalContainer.forContainerScreen(
4141
R.id.panel_container,
42+
// This theme defines custom enter and exit animation styles for panel windows.
43+
dialogThemeResId = R.style.PanelDialog,
4244
modalDecorator = { panelBody ->
4345
PanelBodyWrapper(panelBody.context)
4446
.apply { addView(panelBody) }
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2020 Square Inc.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<set xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:interpolator="@android:anim/decelerate_interpolator"
19+
android:duration="@android:integer/config_mediumAnimTime"
20+
>
21+
22+
<scale
23+
android:fromXScale="0.9"
24+
android:toXScale="1"
25+
android:fromYScale="0.9"
26+
android:toYScale="1"
27+
android:pivotX="50%p"
28+
android:pivotY="50%p"
29+
/>
30+
31+
<alpha
32+
android:fromAlpha="0"
33+
android:toAlpha="1"
34+
/>
35+
36+
</set>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2020 Square Inc.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<set xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:interpolator="@android:anim/accelerate_interpolator"
19+
android:duration="@android:integer/config_mediumAnimTime"
20+
>
21+
22+
<scale
23+
android:fromXScale="1"
24+
android:toXScale="0.9"
25+
android:fromYScale="1"
26+
android:toYScale="0.9"
27+
android:pivotX="50%p"
28+
android:pivotY="50%p"
29+
/>
30+
31+
<alpha
32+
android:fromAlpha="1"
33+
android:toAlpha="0"
34+
/>
35+
36+
</set>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2020 Square Inc.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<translate xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:duration="@android:integer/config_mediumAnimTime"
19+
android:fromYDelta="100%p"
20+
android:interpolator="@android:anim/decelerate_interpolator"
21+
android:toYDelta="0"
22+
/>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2020 Square Inc.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<translate xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:duration="@android:integer/config_shortAnimTime"
19+
android:fromYDelta="0"
20+
android:interpolator="@android:anim/accelerate_interpolator"
21+
android:toYDelta="100%p"
22+
/>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2019 Square Inc.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
217
<resources>
318
<bool name="is_tablet">false</bool>
419
</resources>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2020 Square Inc.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<resources>
18+
19+
<style name="PanelDialog">
20+
<item name="android:windowAnimationStyle">@style/PanelDialogAnimation</item>
21+
<!-- For some reason this is required to get our windowEnterAnimation honored. -->
22+
<item name="android:windowIsFloating">true</item>
23+
</style>
24+
25+
<style name="PanelDialogAnimation">
26+
<item name="android:windowEnterAnimation">@anim/panel_enter</item>
27+
<item name="android:windowExitAnimation">@anim/panel_exit</item>
28+
</style>
29+
30+
</resources>

kotlin/workflow-ui-android/src/main/java/com/squareup/workflow/ui/backstack/BackStackContainer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import android.view.Gravity
2222
import android.view.View
2323
import android.view.ViewGroup
2424
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
25+
import android.view.animation.AccelerateDecelerateInterpolator
2526
import android.widget.FrameLayout
2627
import androidx.transition.Scene
2728
import androidx.transition.Slide
@@ -129,6 +130,7 @@ open class BackStackContainer @JvmOverloads constructor(
129130
val transition = TransitionSet()
130131
.addTransition(Slide(outEdge).addTarget(oldTarget))
131132
.addTransition(Slide(inEdge).addTarget(newTarget))
133+
.setInterpolator(AccelerateDecelerateInterpolator())
132134

133135
TransitionManager.go(Scene(this, newView), transition)
134136
return

0 commit comments

Comments
 (0)