导航菜单

页面标题

页面副标题

aeroLINE CREW v5.0.1 - ScreenStackFragment.java 源代码

正在查看: aeroLINE CREW v5.0.1 应用的 ScreenStackFragment.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.swmansion.rnscreens;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import com.facebook.react.uimanager.PixelUtil;
import com.google.android.material.appbar.AppBarLayout;

public class ScreenStackFragment extends ScreenFragment {
    private static final float TOOLBAR_ELEVATION = PixelUtil.toPixelFromDIP(4.0f);
    private AppBarLayout mAppBarLayout;
    private boolean mIsTranslucent;
    private boolean mShadowHidden;
    private Toolbar mToolbar;

    private static class NotifyingCoordinatorLayout extends CoordinatorLayout {
        private Animation.AnimationListener mAnimationListener;
        private final ScreenFragment mFragment;

        public NotifyingCoordinatorLayout(Context context, ScreenFragment screenFragment) {
            super(context);
            this.mAnimationListener = new Animation.AnimationListener() {
                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationStart(Animation animation) {
                    NotifyingCoordinatorLayout.this.mFragment.onViewAnimationStart();
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    NotifyingCoordinatorLayout.this.mFragment.onViewAnimationEnd();
                }
            };
            this.mFragment = screenFragment;
        }

        public void startAnimation(Animation animation) {
            AnimationSet animationSet = new AnimationSet(true);
            animationSet.addAnimation(animation);
            animationSet.setAnimationListener(this.mAnimationListener);
            super.startAnimation(animationSet);
        }
    }

    public ScreenStackFragment(Screen screen) {
        super(screen);
    }

    public ScreenStackFragment() {
        throw new IllegalStateException("ScreenStack fragments should never be restored. Follow instructions from https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067 to properly configure your main activity.");
    }

    public void removeToolbar() {
        Toolbar toolbar;
        if (this.mAppBarLayout != null && (toolbar = this.mToolbar) != null) {
            AppBarLayout parent = toolbar.getParent();
            AppBarLayout appBarLayout = this.mAppBarLayout;
            if (parent == appBarLayout) {
                appBarLayout.removeView(this.mToolbar);
            }
        }
        this.mToolbar = null;
    }

    public void setToolbar(Toolbar toolbar) {
        AppBarLayout appBarLayout = this.mAppBarLayout;
        if (appBarLayout != null) {
            appBarLayout.addView(toolbar);
        }
        this.mToolbar = toolbar;
        AppBarLayout.LayoutParams layoutParams = new AppBarLayout.LayoutParams(-1, -2);
        layoutParams.setScrollFlags(0);
        this.mToolbar.setLayoutParams(layoutParams);
    }

    public void setToolbarShadowHidden(boolean z) {
        if (this.mShadowHidden != z) {
            this.mAppBarLayout.setTargetElevation(z ? 0.0f : TOOLBAR_ELEVATION);
            this.mShadowHidden = z;
        }
    }

    public void setToolbarTranslucent(boolean z) {
        if (this.mIsTranslucent != z) {
            this.mScreenView.getLayoutParams().setBehavior(z ? null : new AppBarLayout.ScrollingViewBehavior());
            this.mIsTranslucent = z;
        }
    }

    @Override
    public void onContainerUpdate() {
        ScreenStackHeaderConfig headerConfig = getScreen().getHeaderConfig();
        if (headerConfig != null) {
            headerConfig.onUpdate();
        }
    }

    @Override
    public void onViewAnimationEnd() {
        super.onViewAnimationEnd();
        notifyViewAppearTransitionEnd();
    }

    public Animation onCreateAnimation(int i, boolean z, int i2) {
        if (i != 0 || isHidden()) {
            return null;
        }
        ScreenContainer container = getScreen().getContainer();
        boolean z2 = container != null && container.isNested();
        if (z) {
            if (z2) {
                return null;
            }
            dispatchOnWillAppear();
            dispatchOnAppear();
            return null;
        }
        if (!z2) {
            dispatchOnWillDisappear();
            dispatchOnDisappear();
        }
        notifyViewAppearTransitionEnd();
        return null;
    }

    private void notifyViewAppearTransitionEnd() {
        ViewParent parent = getView() != null ? getView().getParent() : null;
        if (parent instanceof ScreenStack) {
            ((ScreenStack) parent).onViewAppearTransitionEnd();
        }
    }

    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        CoordinatorLayout notifyingCoordinatorLayout = new NotifyingCoordinatorLayout(getContext(), this);
        ViewGroup.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(-1, -1);
        layoutParams.setBehavior(this.mIsTranslucent ? null : new AppBarLayout.ScrollingViewBehavior());
        this.mScreenView.setLayoutParams(layoutParams);
        notifyingCoordinatorLayout.addView(recycleView(this.mScreenView));
        AppBarLayout appBarLayout = new AppBarLayout(getContext());
        this.mAppBarLayout = appBarLayout;
        appBarLayout.setBackgroundColor(0);
        this.mAppBarLayout.setLayoutParams(new AppBarLayout.LayoutParams(-1, -2));
        notifyingCoordinatorLayout.addView(this.mAppBarLayout);
        if (this.mShadowHidden) {
            this.mAppBarLayout.setTargetElevation(0.0f);
        }
        Toolbar toolbar = this.mToolbar;
        if (toolbar != null) {
            this.mAppBarLayout.addView(recycleView(toolbar));
        }
        return notifyingCoordinatorLayout;
    }

    public boolean isDismissable() {
        return this.mScreenView.isGestureEnabled();
    }

    public boolean canNavigateBack() {
        ScreenContainer container = this.mScreenView.getContainer();
        if (container instanceof ScreenStack) {
            if (((ScreenStack) container).getRootScreen() != getScreen()) {
                return true;
            }
            Fragment parentFragment = getParentFragment();
            if (parentFragment instanceof ScreenStackFragment) {
                return ((ScreenStackFragment) parentFragment).canNavigateBack();
            }
            return false;
        }
        throw new IllegalStateException("ScreenStackFragment added into a non-stack container");
    }

    public void dismiss() {
        ScreenContainer container = this.mScreenView.getContainer();
        if (container instanceof ScreenStack) {
            ((ScreenStack) container).dismiss(this);
            return;
        }
        throw new IllegalStateException("ScreenStackFragment added into a non-stack container");
    }
}