Skip to content

Commit

Permalink
feat: animation on step state changed
Browse files Browse the repository at this point in the history
  • Loading branch information
aikrq committed Dec 4, 2024
1 parent ea20f86 commit d115523
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.transition.TransitionManager;

import com.google.android.material.transition.MaterialSharedAxis;

import mod.remaker.activity.projectwizard.ProjectWizardActivity;

import pro.sketchware.R;
Expand Down Expand Up @@ -50,6 +54,8 @@ public boolean presentStep(IWizardLayout.WizardParams params) {
wrappedView.setLayoutParams(new LayoutParams(-1, -1));
steps.add(step);

buildLayoutAnimation(true);

FrameLayout temp = containerView;
containerView = containerViewBack;
containerViewBack = temp;
Expand Down Expand Up @@ -116,6 +122,8 @@ public boolean closeLastStep() {
stepView = previousStep.onCreateView(activity);
}

buildLayoutAnimation(false);

containerView.setVisibility(View.VISIBLE);
removeViewFromParent(stepView);
containerView.addView(stepView);
Expand Down Expand Up @@ -205,10 +213,7 @@ public void bringToFront(int position) {
}

public WizardStep getLastStep() {
if (steps.isEmpty()) {
return null;
}
return steps.get(steps.size() - 1);
return !steps.isEmpty() ? steps.get(steps.size() - 1) : null;
}

private void presentStepInternalRemoveOld(boolean removeLast, WizardStep step) {
Expand Down Expand Up @@ -286,4 +291,9 @@ private void checkStepViewBackground(View view) {
view.setBackgroundColor(ThemeUtils.getColor(view, R.attr.colorSurface));
}
}

private void buildLayoutAnimation(final boolean open) {
MaterialSharedAxis transition = new MaterialSharedAxis(MaterialSharedAxis.X, open);
TransitionManager.beginDelayedTransition(this, transition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final View onCreateView(Context context) {

// Make sure that method is called after `setParentLayout(IWizardLayout)`.
private void configureStep(WizardStepBinding binding) {
binding.toolbar.setNavigationOnClickListener(v -> {
binding.btnBack.setOnClickListener(v -> {
if (getParentActivity() != null) {
getParentActivity().onBackPressed();
}
Expand Down Expand Up @@ -89,10 +89,7 @@ public boolean onBackPressed() {
}

public Activity getParentActivity() {
if (parentLayout != null) {
return parentLayout.getParentActivity();
}
return null;
return parentLayout != null ? parentLayout.getParentActivity() : null;
}

public Context getContext() {
Expand Down
103 changes: 54 additions & 49 deletions app/src/main/res/layout/wizard_step.xml
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionGroup="true">
android:layout_height="match_parent">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationIcon="?attr/homeAsUpIndicator"
app:navigationIconTint="?attr/colorOnSurface" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="64dp"
android:ellipsize="end"
android:maxLines="2"
android:textAppearance="?attr/textAppearanceHeadlineMedium"
android:textColor="?attr/colorOnSurface"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" />
<ImageView
android:id="@+id/btn_back"
android:layout_width="@dimen/mtrl_min_touch_target_size"
android:layout_height="@dimen/mtrl_min_touch_target_size"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="?attr/colorOnSurface" />

<TextView
android:id="@+id/message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:textAppearance="?attr/textAppearanceBodyMedium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title" />
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="48dp"
android:ellipsize="end"
android:maxLines="2"
android:textAppearance="@style/TextAppearance.SketchwarePro.CollapsingToolbar.Expanded"
android:textColor="?attr/colorOnSurface"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_back" />

<FrameLayout
android:id="@+id/container"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="24dp"
android:layout_marginTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/message" />
<TextView
android:id="@+id/message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:textAppearance="?attr/textAppearanceBodyMedium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title" />

</androidx.constraintlayout.widget.ConstraintLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="24dp"
android:layout_marginTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/message" />

</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/wizard_step_additional.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingEnd="24dp"
android:paddingStart="24dp">
android:paddingStart="24dp"
android:transitionGroup="true">

<TextView
android:layout_width="match_parent"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/wizard_step_basic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingEnd="24dp"
android:paddingStart="24dp">
android:paddingStart="24dp"
android:transitionGroup="true">

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_app_name"
Expand Down

0 comments on commit d115523

Please sign in to comment.