导航菜单

页面标题

页面副标题

Pulsar v1.0.0 - ScreenFragment.java 源代码

正在查看: Pulsar v1.0.0 应用的 ScreenFragment.java JAVA 源代码文件

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


package com.swmansion.rnscreens;

import android.annotation.SuppressLint;
import android.app.Activity;
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.widget.FrameLayout;
import androidx.fragment.app.Fragment;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.uimanager.UIManagerHelper;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.EventDispatcher;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import kotlin.Metadata;
import kotlin.i0;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.p1;
import org.jetbrains.annotations.NotNull;

@p1({"SMAP\nScreenFragment.kt\nKotlin\n*S Kotlin\n*F\n+ 1 ScreenFragment.kt\ncom/swmansion/rnscreens/ScreenFragment\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n+ 3 _Collections.kt\nkotlin/collections/CollectionsKt___CollectionsKt\n*L\n1#1,335:1\n1#2:336\n766#3:337\n857#3,2:338\n1855#3,2:340\n*S KotlinDebug\n*F\n+ 1 ScreenFragment.kt\ncom/swmansion/rnscreens/ScreenFragment\n*L\n215#1:337\n215#1:338,2\n215#1:340,2\n*E\n"})
@Metadata(d1 = {"\u0000j\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\b\u0005\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0010\u0007\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\u0010!\n\u0002\b\u0013\b\u0016\u0018\u0000 \u00042\u00020\u00012\u00020\u0002:\u0003-\u0006HB\t\b\u0016¢\u0006\u0004\bF\u00104B\u0011\b\u0017\u0012\u0006\u0010G\u001a\u00020,¢\u0006\u0004\bF\u00102J\b\u0010\u0004\u001a\u00020\u0003H\u0002J\b\u0010\u0005\u001a\u00020\u0003H\u0002J\b\u0010\u0006\u001a\u00020\u0003H\u0002J\b\u0010\u0007\u001a\u00020\u0003H\u0002J\b\u0010\b\u001a\u00020\u0003H\u0002J\u0010\u0010\u000b\u001a\u00020\u00032\u0006\u0010\n\u001a\u00020\tH\u0002J\b\u0010\f\u001a\u00020\u0003H\u0016J&\u0010\u0014\u001a\u0004\u0018\u00010\u00132\u0006\u0010\u000e\u001a\u00020\r2\b\u0010\u0010\u001a\u0004\u0018\u00010\u000f2\b\u0010\u0012\u001a\u0004\u0018\u00010\u0011H\u0016J\b\u0010\u0015\u001a\u00020\u0003H\u0016J\n\u0010\u0017\u001a\u0004\u0018\u00010\u0016H\u0016J\n\u0010\u0019\u001a\u0004\u0018\u00010\u0018H\u0016J\u0010\u0010\u001c\u001a\u00020\t2\u0006\u0010\u001b\u001a\u00020\u001aH\u0016J\u0010\u0010\u001d\u001a\u00020\u00032\u0006\u0010\u001b\u001a\u00020\u001aH\u0016J\u0018\u0010\u001f\u001a\u00020\u00032\u0006\u0010\u001b\u001a\u00020\u001a2\u0006\u0010\u001e\u001a\u00020\u0002H\u0016J\u0010\u0010 \u001a\u00020\u00032\u0006\u0010\u001b\u001a\u00020\u001aH\u0016J\b\u0010!\u001a\u00020\u0003H\u0016J\u0018\u0010%\u001a\u00020\u00032\u0006\u0010#\u001a\u00020\"2\u0006\u0010$\u001a\u00020\tH\u0016J\u0010\u0010'\u001a\u00020\u00032\u0006\u0010\u0010\u001a\u00020&H\u0016J\u0010\u0010(\u001a\u00020\u00032\u0006\u0010\u0010\u001a\u00020&H\u0016J\b\u0010)\u001a\u00020\u0003H\u0016J\b\u0010*\u001a\u00020\u0003H\u0016J\b\u0010+\u001a\u00020\u0003H\u0016R(\u00105\u001a\u00020,8\u0016@\u0016X\u0096.¢\u0006\u0018\n\u0004\b-\u0010.\u0012\u0004\b3\u00104\u001a\u0004\b/\u00100\"\u0004\b1\u00102R \u0010:\u001a\b\u0012\u0004\u0012\u00020&068\u0016X\u0096\u0004¢\u0006\f\n\u0004\b\u0006\u00107\u001a\u0004\b8\u00109R\u0016\u0010<\u001a\u00020\t8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\b\u0010;R\u0016\u0010>\u001a\u00020\"8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0005\u0010=R\u0016\u0010?\u001a\u00020\t8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0007\u0010;R\u0016\u0010@\u001a\u00020\t8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u000b\u0010;R\u0016\u0010B\u001a\u00020\t8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\bA\u0010;R\u0014\u0010E\u001a\u00020\u00018VX\u0096\u0004¢\u0006\u0006\u001a\u0004\bC\u0010D¨\u0006I"}, d2 = {"Lcom/swmansion/rnscreens/ScreenFragment;", "Landroidx/fragment/app/Fragment;", "Lcom/swmansion/rnscreens/k;", "", "i", "d", "b", "e", "c", "", "animationEnd", "f", "onResume", "Landroid/view/LayoutInflater;", "inflater", "Landroid/view/ViewGroup;", "container", "Landroid/os/Bundle;", "savedInstanceState", "Landroid/view/View;", "onCreateView", "onContainerUpdate", "Landroid/app/Activity;", "tryGetActivity", "Lcom/facebook/react/bridge/ReactContext;", "tryGetContext", "Lcom/swmansion/rnscreens/ScreenFragment$b;", "event", "canDispatchLifecycleEvent", "updateLastEventDispatched", "fragmentWrapper", "dispatchLifecycleEvent", "dispatchLifecycleEventInChildContainers", "dispatchHeaderBackButtonClickedEvent", "", "alpha", "closing", "dispatchTransitionProgressEvent", "Lcom/swmansion/rnscreens/ScreenContainer;", "addChildScreenContainer", "removeChildScreenContainer", "onViewAnimationStart", "onViewAnimationEnd", "onDestroy", "Lcom/swmansion/rnscreens/Screen;", "a", "Lcom/swmansion/rnscreens/Screen;", "getScreen", "()Lcom/swmansion/rnscreens/Screen;", "setScreen", "(Lcom/swmansion/rnscreens/Screen;)V", "getScreen$annotations", "()V", "screen", "", "Ljava/util/List;", "getChildScreenContainers", "()Ljava/util/List;", "childScreenContainers", "Z", "shouldUpdateOnResume", "F", "transitionProgress", "canDispatchWillAppear", "canDispatchAppear", "g", "isTransitioning", "getFragment", "()Landroidx/fragment/app/Fragment;", "fragment", "<init>", "screenView", "ScreensFrameLayout", "react-native-screens_release"}, k = 1, mv = {1, 9, 0})
public class ScreenFragment extends Fragment implements k {

    @NotNull
    public static final Companion INSTANCE = new Companion(null);

    public Screen screen;

    @NotNull
    private final List<ScreenContainer> childScreenContainers;

    private boolean shouldUpdateOnResume;

    private float transitionProgress;

    private boolean canDispatchWillAppear;

    private boolean canDispatchAppear;

    private boolean isTransitioning;

    @Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\b\u0002\u0018\u00002\u00020\u0001B\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\b\u0010\u0005\u001a\u00020\u0006H\u0016¨\u0006\u0007"}, d2 = {"Lcom/swmansion/rnscreens/ScreenFragment$ScreensFrameLayout;", "Landroid/widget/FrameLayout;", "context", "Landroid/content/Context;", "(Landroid/content/Context;)V", "clearFocus", "", "react-native-screens_release"}, k = 1, mv = {1, 9, 0}, xi = 48)
    private static final class ScreensFrameLayout extends FrameLayout {
        public ScreensFrameLayout(@NotNull Context context) {
            super(context);
            Intrinsics.checkNotNullParameter(context, "context");
        }

        @Override
        public void clearFocus() {
            if (getVisibility() != 4) {
                super.clearFocus();
            }
        }
    }

    public static final class Companion {
        private Companion() {
        }

        @m7.n
        @NotNull
        protected final View a(@NotNull View view) {
            Intrinsics.checkNotNullParameter(view, "view");
            ViewParent parent = view.getParent();
            if (parent != null) {
                ViewGroup viewGroup = (ViewGroup) parent;
                viewGroup.endViewTransition(view);
                viewGroup.removeView(view);
            }
            view.setVisibility(0);
            return view;
        }

        public final short getCoalescingKey(float f) {
            return (short) (f == 0.0f ? 1 : f == 1.0f ? 2 : 3);
        }

        public Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }
    }

    public static final class b {
        public static final b a = new b("DID_APPEAR", 0);
        public static final b b = new b("WILL_APPEAR", 1);
        public static final b c = new b("DID_DISAPPEAR", 2);
        public static final b d = new b("WILL_DISAPPEAR", 3);
        private static final b[] e;
        private static final kotlin.enums.a f;

        static {
            b[] a2 = a();
            e = a2;
            f = kotlin.enums.c.enumEntries(a2);
        }

        private b(String str, int i) {
        }

        private static final b[] a() {
            return new b[]{a, b, c, d};
        }

        @NotNull
        public static kotlin.enums.a<b> getEntries() {
            return f;
        }

        public static b valueOf(String str) {
            return (b) Enum.valueOf(b.class, str);
        }

        public static b[] values() {
            return (b[]) e.clone();
        }
    }

    public class c {
        public static final int[] a;

        static {
            int[] iArr = new int[b.values().length];
            try {
                iArr[b.b.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[b.a.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[b.d.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[b.c.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            a = iArr;
        }
    }

    public ScreenFragment() {
        this.childScreenContainers = new ArrayList();
        this.transitionProgress = -1.0f;
        this.canDispatchWillAppear = true;
        this.canDispatchAppear = true;
        throw new IllegalStateException("Screen 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.");
    }

    private final void b() {
        dispatchLifecycleEvent(b.a, this);
        dispatchTransitionProgressEvent(1.0f, false);
    }

    private final void c() {
        dispatchLifecycleEvent(b.c, this);
        dispatchTransitionProgressEvent(1.0f, true);
    }

    private final void d() {
        dispatchLifecycleEvent(b.b, this);
        dispatchTransitionProgressEvent(0.0f, false);
    }

    private final void e() {
        dispatchLifecycleEvent(b.d, this);
        dispatchTransitionProgressEvent(0.0f, true);
    }

    private final void f(final boolean animationEnd) {
        this.isTransitioning = !animationEnd;
        Fragment parentFragment = getParentFragment();
        if (parentFragment == null || ((parentFragment instanceof ScreenFragment) && !((ScreenFragment) parentFragment).isTransitioning)) {
            if (isResumed()) {
                UiThreadUtil.runOnUiThread(new Runnable() {
                    @Override
                    public final void run() {
                        ScreenFragment.g(animationEnd, this);
                    }
                });
            } else if (animationEnd) {
                c();
            } else {
                e();
            }
        }
    }

    public static final void g(boolean z, ScreenFragment this$0) {
        Intrinsics.checkNotNullParameter(this$0, "this$0");
        if (z) {
            this$0.b();
        } else {
            this$0.d();
        }
    }

    public static void getScreen$annotations() {
    }

    @m7.n
    @NotNull
    protected static final View h(@NotNull View view) {
        return INSTANCE.a(view);
    }

    private final void i() {
        Activity activity = getActivity();
        if (activity == null) {
            this.shouldUpdateOnResume = true;
        } else {
            r.a.trySetWindowTraits$react_native_screens_release(getScreen(), activity, tryGetContext());
        }
    }

    @Override
    public void addChildScreenContainer(@NotNull ScreenContainer container) {
        Intrinsics.checkNotNullParameter(container, "container");
        getChildScreenContainers().add(container);
    }

    @Override
    public boolean canDispatchLifecycleEvent(@NotNull b event) {
        Intrinsics.checkNotNullParameter(event, "event");
        int i = c.a[event.ordinal()];
        if (i == 1) {
            return this.canDispatchWillAppear;
        }
        if (i == 2) {
            return this.canDispatchAppear;
        }
        if (i != 3) {
            if (i != 4) {
                throw new i0();
            }
            if (!this.canDispatchAppear) {
                return true;
            }
        } else if (!this.canDispatchWillAppear) {
            return true;
        }
        return false;
    }

    @Override
    public void dispatchHeaderBackButtonClickedEvent() {
        ReactContext context = getScreen().getContext();
        Intrinsics.checkNotNull(context, "null cannot be cast to non-null type com.facebook.react.bridge.ReactContext");
        ReactContext reactContext = context;
        int surfaceId = UIManagerHelper.getSurfaceId(reactContext);
        EventDispatcher eventDispatcherForReactTag = UIManagerHelper.getEventDispatcherForReactTag(reactContext, getScreen().getId());
        if (eventDispatcherForReactTag != null) {
            eventDispatcherForReactTag.dispatchEvent(new com.swmansion.rnscreens.events.b(surfaceId, getScreen().getId()));
        }
    }

    @Override
    public void dispatchLifecycleEvent(@NotNull b event, @NotNull k fragmentWrapper) {
        Event iVar;
        Intrinsics.checkNotNullParameter(event, "event");
        Intrinsics.checkNotNullParameter(fragmentWrapper, "fragmentWrapper");
        Fragment fragment = fragmentWrapper.getFragment();
        if (fragment instanceof ScreenStackFragment) {
            ScreenStackFragment screenStackFragment = (ScreenStackFragment) fragment;
            if (screenStackFragment.canDispatchLifecycleEvent(event)) {
                Screen screen = screenStackFragment.getScreen();
                fragmentWrapper.updateLastEventDispatched(event);
                int surfaceId = UIManagerHelper.getSurfaceId(screen);
                int i = c.a[event.ordinal()];
                if (i == 1) {
                    iVar = new com.swmansion.rnscreens.events.i(surfaceId, screen.getId());
                } else if (i == 2) {
                    iVar = new com.swmansion.rnscreens.events.e(surfaceId, screen.getId());
                } else if (i == 3) {
                    iVar = new com.swmansion.rnscreens.events.j(surfaceId, screen.getId());
                } else {
                    if (i != 4) {
                        throw new i0();
                    }
                    iVar = new com.swmansion.rnscreens.events.f(surfaceId, screen.getId());
                }
                ReactContext context = getScreen().getContext();
                Intrinsics.checkNotNull(context, "null cannot be cast to non-null type com.facebook.react.bridge.ReactContext");
                EventDispatcher eventDispatcherForReactTag = UIManagerHelper.getEventDispatcherForReactTag(context, getScreen().getId());
                if (eventDispatcherForReactTag != null) {
                    eventDispatcherForReactTag.dispatchEvent(iVar);
                }
                fragmentWrapper.dispatchLifecycleEventInChildContainers(event);
            }
        }
    }

    @Override
    public void dispatchLifecycleEventInChildContainers(@NotNull b event) {
        k fragmentWrapper;
        Intrinsics.checkNotNullParameter(event, "event");
        List<ScreenContainer> childScreenContainers = getChildScreenContainers();
        ArrayList arrayList = new ArrayList();
        for (Object obj : childScreenContainers) {
            if (((ScreenContainer) obj).getScreenCount() > 0) {
                arrayList.add(obj);
            }
        }
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            Screen topScreen = ((ScreenContainer) it.next()).getTopScreen();
            if (topScreen != null && (fragmentWrapper = topScreen.getFragmentWrapper()) != null) {
                dispatchLifecycleEvent(event, fragmentWrapper);
            }
        }
    }

    @Override
    public void dispatchTransitionProgressEvent(float alpha, boolean closing) {
        if (!(this instanceof ScreenStackFragment) || this.transitionProgress == alpha) {
            return;
        }
        float max = Math.max(0.0f, Math.min(1.0f, alpha));
        this.transitionProgress = max;
        short coalescingKey = INSTANCE.getCoalescingKey(max);
        ScreenContainer container = getScreen().getContainer();
        boolean goingForward = container instanceof ScreenStack ? ((ScreenStack) container).getGoingForward() : false;
        ReactContext context = getScreen().getContext();
        Intrinsics.checkNotNull(context, "null cannot be cast to non-null type com.facebook.react.bridge.ReactContext");
        ReactContext reactContext = context;
        EventDispatcher eventDispatcherForReactTag = UIManagerHelper.getEventDispatcherForReactTag(reactContext, getScreen().getId());
        if (eventDispatcherForReactTag != null) {
            eventDispatcherForReactTag.dispatchEvent(new com.swmansion.rnscreens.events.h(UIManagerHelper.getSurfaceId(reactContext), getScreen().getId(), this.transitionProgress, closing, goingForward, coalescingKey));
        }
    }

    @Override
    @NotNull
    public List<ScreenContainer> getChildScreenContainers() {
        return this.childScreenContainers;
    }

    @Override
    @NotNull
    public Fragment getFragment() {
        return this;
    }

    @Override
    @NotNull
    public Screen getScreen() {
        Screen screen = this.screen;
        if (screen != null) {
            return screen;
        }
        Intrinsics.throwUninitializedPropertyAccessException("screen");
        return null;
    }

    @Override
    public void onContainerUpdate() {
        i();
    }

    @f8.d
    public View onCreateView(@NotNull LayoutInflater inflater, @f8.d ViewGroup container, @f8.d Bundle savedInstanceState) {
        Intrinsics.checkNotNullParameter(inflater, "inflater");
        getScreen().setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
        Context context = getContext();
        if (context == null) {
            return null;
        }
        ScreensFrameLayout screensFrameLayout = new ScreensFrameLayout(context);
        screensFrameLayout.addView(h(getScreen()));
        return screensFrameLayout;
    }

    public void onDestroy() {
        super.onDestroy();
        ScreenContainer container = getScreen().getContainer();
        if (container == null || !container.hasScreen(this)) {
            ReactContext context = getScreen().getContext();
            if (context instanceof ReactContext) {
                int surfaceId = UIManagerHelper.getSurfaceId(context);
                EventDispatcher eventDispatcherForReactTag = UIManagerHelper.getEventDispatcherForReactTag(context, getScreen().getId());
                if (eventDispatcherForReactTag != null) {
                    eventDispatcherForReactTag.dispatchEvent(new com.swmansion.rnscreens.events.g(surfaceId, getScreen().getId()));
                }
            }
        }
        getChildScreenContainers().clear();
    }

    public void onResume() {
        super.onResume();
        if (this.shouldUpdateOnResume) {
            this.shouldUpdateOnResume = false;
            r.a.trySetWindowTraits$react_native_screens_release(getScreen(), tryGetActivity(), tryGetContext());
        }
    }

    @Override
    public void onViewAnimationEnd() {
        f(true);
    }

    @Override
    public void onViewAnimationStart() {
        f(false);
    }

    @Override
    public void removeChildScreenContainer(@NotNull ScreenContainer container) {
        Intrinsics.checkNotNullParameter(container, "container");
        getChildScreenContainers().remove(container);
    }

    @Override
    public void setScreen(@NotNull Screen screen) {
        Intrinsics.checkNotNullParameter(screen, "<set-?>");
        this.screen = screen;
    }

    @Override
    @f8.d
    public Activity tryGetActivity() {
        Fragment fragment;
        androidx.fragment.app.j activity;
        androidx.fragment.app.j activity2 = getActivity();
        if (activity2 != null) {
            return activity2;
        }
        ReactContext context = getScreen().getContext();
        if (context instanceof ReactContext) {
            ReactContext reactContext = context;
            if (reactContext.getCurrentActivity() != null) {
                return reactContext.getCurrentActivity();
            }
        }
        for (ViewParent container = getScreen().getContainer(); container != null; container = container.getParent()) {
            if ((container instanceof Screen) && (fragment = ((Screen) container).getFragment()) != null && (activity = fragment.getActivity()) != null) {
                return activity;
            }
        }
        return null;
    }

    @Override
    @f8.d
    public ReactContext tryGetContext() {
        Context context;
        if (getContext() instanceof ReactContext) {
            context = getContext();
        } else {
            if (!(getScreen().getContext() instanceof ReactContext)) {
                for (ViewParent container = getScreen().getContainer(); container != null; container = container.getParent()) {
                    if (container instanceof Screen) {
                        Screen screen = (Screen) container;
                        if (screen.getContext() instanceof ReactContext) {
                            context = screen.getContext();
                        }
                    }
                }
                return null;
            }
            context = getScreen().getContext();
        }
        Intrinsics.checkNotNull(context, "null cannot be cast to non-null type com.facebook.react.bridge.ReactContext");
        return (ReactContext) context;
    }

    @Override
    public void updateLastEventDispatched(@NotNull b event) {
        Intrinsics.checkNotNullParameter(event, "event");
        int i = c.a[event.ordinal()];
        if (i == 1) {
            this.canDispatchWillAppear = false;
            return;
        }
        if (i == 2) {
            this.canDispatchAppear = false;
        } else if (i == 3) {
            this.canDispatchWillAppear = true;
        } else {
            if (i != 4) {
                return;
            }
            this.canDispatchAppear = true;
        }
    }

    @SuppressLint({"ValidFragment"})
    public ScreenFragment(@NotNull Screen screenView) {
        Intrinsics.checkNotNullParameter(screenView, "screenView");
        this.childScreenContainers = new ArrayList();
        this.transitionProgress = -1.0f;
        this.canDispatchWillAppear = true;
        this.canDispatchAppear = true;
        setScreen(screenView);
    }
}