导航菜单

页面标题

页面副标题

Housing v14.7.8 - ScreenModalFragment.java 源代码

正在查看: Housing v14.7.8 应用的 ScreenModalFragment.java JAVA 源代码文件

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


package com.swmansion.rnscreens;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.WindowManager;
import android.view.WindowMetrics;
import android.widget.FrameLayout;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.p;
import androidx.work.impl.utils.h;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.uimanager.RootView;
import com.facebook.react.uimanager.UIManagerHelper;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.j;
import com.google.android.material.bottomsheet.k;
import com.swmansion.rnscreens.ScreenFragment;
import com.swmansion.rnscreens.bottomsheet.BottomSheetDialogRootView;
import com.swmansion.rnscreens.bottomsheet.BottomSheetDialogScreen;
import com.swmansion.rnscreens.bottomsheet.SheetUtils;
import com.swmansion.rnscreens.events.ScreenDismissedEvent;
import com.swmansion.rnscreens.ext.ViewExtKt;
import java.util.ArrayList;
import kotlin.Metadata;
import kotlin.collections.t;
import kotlin.jvm.internal.SourceDebugExtension;
import kotlin.jvm.internal.r;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@Metadata(d1 = {"\u0000º\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\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\u0003\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u0007\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\u0018\u0000 d2\u00020\u00012\u00020\u0002:\u0001dB\t\b\u0016¢\u0006\u0004\b\u0003\u0010\u0004B\u0011\b\u0016\u0012\u0006\u0010\u0006\u001a\u00020\u0005¢\u0006\u0004\b\u0003\u0010\u0007J\u0019\u0010\u000b\u001a\u00020\n2\b\u0010\t\u001a\u0004\u0018\u00010\bH\u0016¢\u0006\u0004\b\u000b\u0010\fJ\u0019\u0010\u000e\u001a\u00020\r2\b\u0010\t\u001a\u0004\u0018\u00010\bH\u0016¢\u0006\u0004\b\u000e\u0010\u000fJ-\u0010\u0015\u001a\u0004\u0018\u00010\u00142\u0006\u0010\u0011\u001a\u00020\u00102\b\u0010\u0013\u001a\u0004\u0018\u00010\u00122\b\u0010\t\u001a\u0004\u0018\u00010\bH\u0016¢\u0006\u0004\b\u0015\u0010\u0016J\u000f\u0010\u0017\u001a\u00020\nH\u0016¢\u0006\u0004\b\u0017\u0010\u0004J\u000f\u0010\u0019\u001a\u00020\u0018H\u0016¢\u0006\u0004\b\u0019\u0010\u001aJ\u0017\u0010\u001c\u001a\u00020\n2\u0006\u0010\u0013\u001a\u00020\u001bH\u0016¢\u0006\u0004\b\u001c\u0010\u001dJ\u0017\u0010\u001e\u001a\u00020\n2\u0006\u0010\u0013\u001a\u00020\u001bH\u0016¢\u0006\u0004\b\u001e\u0010\u001dJ\u000f\u0010\u001f\u001a\u00020\nH\u0016¢\u0006\u0004\b\u001f\u0010\u0004J\u000f\u0010 \u001a\u00020\nH\u0016¢\u0006\u0004\b \u0010\u0004J\u000f\u0010!\u001a\u00020\nH\u0016¢\u0006\u0004\b!\u0010\u0004J\u0011\u0010#\u001a\u0004\u0018\u00010\"H\u0016¢\u0006\u0004\b#\u0010$J\u0011\u0010&\u001a\u0004\u0018\u00010%H\u0016¢\u0006\u0004\b&\u0010'J\u0017\u0010*\u001a\u00020\u00182\u0006\u0010)\u001a\u00020(H\u0016¢\u0006\u0004\b*\u0010+J\u0017\u0010,\u001a\u00020\n2\u0006\u0010)\u001a\u00020(H\u0016¢\u0006\u0004\b,\u0010-J\u001f\u00100\u001a\u00020\n2\u0006\u0010)\u001a\u00020(2\u0006\u0010/\u001a\u00020.H\u0016¢\u0006\u0004\b0\u00101J\u0017\u00102\u001a\u00020\n2\u0006\u0010)\u001a\u00020(H\u0016¢\u0006\u0004\b2\u0010-J\u000f\u00103\u001a\u00020\nH\u0016¢\u0006\u0004\b3\u0010\u0004J\u001f\u00107\u001a\u00020\n2\u0006\u00105\u001a\u0002042\u0006\u00106\u001a\u00020\u0018H\u0016¢\u0006\u0004\b7\u00108J\u000f\u00109\u001a\u00020\nH\u0016¢\u0006\u0004\b9\u0010\u0004J\u000f\u0010:\u001a\u00020\nH\u0016¢\u0006\u0004\b:\u0010\u0004J\u0017\u0010=\u001a\u00020\n2\u0006\u0010<\u001a\u00020;H\u0016¢\u0006\u0004\b=\u0010>J\u0017\u0010@\u001a\u00020\n2\u0006\u0010?\u001a\u00020\u0018H\u0016¢\u0006\u0004\b@\u0010AJ\u0017\u0010C\u001a\u00020\n2\u0006\u0010B\u001a\u00020\u0018H\u0016¢\u0006\u0004\bC\u0010AJ\u000f\u0010E\u001a\u00020DH\u0002¢\u0006\u0004\bE\u0010FJ\u0011\u0010H\u001a\u0004\u0018\u00010GH\u0002¢\u0006\u0004\bH\u0010IJ\u000f\u0010J\u001a\u00020\nH\u0002¢\u0006\u0004\bJ\u0010\u0004R\"\u0010\u0006\u001a\u00020\u00058\u0016@\u0016X\u0096.¢\u0006\u0012\n\u0004\b\u0006\u0010K\u001a\u0004\bL\u0010M\"\u0004\bN\u0010\u0007R*\u0010Q\u001a\u0012\u0012\u0004\u0012\u00020\u001b0Oj\b\u0012\u0004\u0012\u00020\u001b`P8\u0016X\u0096\u0004¢\u0006\f\n\u0004\bQ\u0010R\u001a\u0004\bS\u0010TR\u0016\u0010U\u001a\u00020D8\u0002@\u0002X\u0082.¢\u0006\u0006\n\u0004\bU\u0010VR\u0014\u0010Z\u001a\u00020W8VX\u0096\u0004¢\u0006\u0006\u001a\u0004\bX\u0010YR\u0016\u0010\u0013\u001a\u0004\u0018\u00010[8BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b\\\u0010]R\"\u0010c\u001a\u0010\u0012\f\u0012\n `*\u0004\u0018\u00010_0_0^8BX\u0082\u0004¢\u0006\u0006\u001a\u0004\ba\u0010b¨\u0006e"}, d2 = {"Lcom/swmansion/rnscreens/ScreenModalFragment;", "Lcom/google/android/material/bottomsheet/k;", "Lcom/swmansion/rnscreens/ScreenStackFragmentWrapper;", "<init>", "()V", "Lcom/swmansion/rnscreens/Screen;", "screen", "(Lcom/swmansion/rnscreens/Screen;)V", "Landroid/os/Bundle;", "savedInstanceState", "Lzp/j0;", "onCreate", "(Landroid/os/Bundle;)V", "Landroid/app/Dialog;", "onCreateDialog", "(Landroid/os/Bundle;)Landroid/app/Dialog;", "Landroid/view/LayoutInflater;", "inflater", "Landroid/view/ViewGroup;", "container", "Landroid/view/View;", "onCreateView", "(Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Landroid/os/Bundle;)Landroid/view/View;", "dismissFromContainer", "", "canNavigateBack", "()Z", "Lcom/swmansion/rnscreens/ScreenContainer;", "addChildScreenContainer", "(Lcom/swmansion/rnscreens/ScreenContainer;)V", "removeChildScreenContainer", "onContainerUpdate", "onViewAnimationStart", "onViewAnimationEnd", "Landroid/app/Activity;", "tryGetActivity", "()Landroid/app/Activity;", "Lcom/facebook/react/bridge/ReactContext;", "tryGetContext", "()Lcom/facebook/react/bridge/ReactContext;", "Lcom/swmansion/rnscreens/ScreenFragment$ScreenLifecycleEvent;", "event", "canDispatchLifecycleEvent", "(Lcom/swmansion/rnscreens/ScreenFragment$ScreenLifecycleEvent;)Z", "updateLastEventDispatched", "(Lcom/swmansion/rnscreens/ScreenFragment$ScreenLifecycleEvent;)V", "Lcom/swmansion/rnscreens/ScreenFragmentWrapper;", "fragmentWrapper", "dispatchLifecycleEvent", "(Lcom/swmansion/rnscreens/ScreenFragment$ScreenLifecycleEvent;Lcom/swmansion/rnscreens/ScreenFragmentWrapper;)V", "dispatchLifecycleEventInChildContainers", "dispatchHeaderBackButtonClickedEvent", "", "alpha", "closing", "dispatchTransitionProgressEvent", "(FZ)V", "onDestroy", "removeToolbar", "Landroidx/appcompat/widget/Toolbar;", "toolbar", "setToolbar", "(Landroidx/appcompat/widget/Toolbar;)V", "hidden", "setToolbarShadowHidden", "(Z)V", "translucent", "setToolbarTranslucent", "Lcom/google/android/material/bottomsheet/j;", "configureDialogAndBehaviour", "()Lcom/google/android/material/bottomsheet/j;", "", "tryResolveContainerHeight", "()Ljava/lang/Integer;", "configureBehaviour", "Lcom/swmansion/rnscreens/Screen;", "getScreen", "()Lcom/swmansion/rnscreens/Screen;", "setScreen", "Ljava/util/ArrayList;", "Lkotlin/collections/ArrayList;", "childScreenContainers", "Ljava/util/ArrayList;", "getChildScreenContainers", "()Ljava/util/ArrayList;", "sheetDialog", "Lcom/google/android/material/bottomsheet/j;", "Landroidx/fragment/app/p;", "getFragment", "()Landroidx/fragment/app/p;", "fragment", "Lcom/swmansion/rnscreens/ScreenStack;", "getContainer", "()Lcom/swmansion/rnscreens/ScreenStack;", "Lcom/google/android/material/bottomsheet/BottomSheetBehavior;", "Landroid/widget/FrameLayout;", "kotlin.jvm.PlatformType", "getBehavior", "()Lcom/google/android/material/bottomsheet/BottomSheetBehavior;", "behavior", "Companion", "react-native-screens_release"}, k = 1, mv = {2, 0, 0}, xi = 48)
@SourceDebugExtension({"SMAP\nScreenModalFragment.kt\nKotlin\n*S Kotlin\n*F\n+ 1 ScreenModalFragment.kt\ncom/swmansion/rnscreens/ScreenModalFragment\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n*L\n1#1,285:1\n1#2:286\n*E\n"})
public final class ScreenModalFragment extends k implements ScreenStackFragmentWrapper {

    @NotNull
    public static final String TAG = "ScreenModalFragment";

    @NotNull
    private final ArrayList<ScreenContainer> childScreenContainers;
    public Screen screen;
    private j sheetDialog;

    public ScreenModalFragment() {
        this.childScreenContainers = new ArrayList<>();
        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 configureBehaviour() {
        if (tryResolveContainerHeight() == null) {
            throw new IllegalStateException("[RNScreens] Failed to find window height during bottom sheet behaviour configuration");
        }
        BottomSheetBehavior<FrameLayout> behavior = getBehavior();
        behavior.P(true);
        behavior.L(true);
        int size = getScreen().getSheetDetents().size();
        if (size == 1) {
            BottomSheetBehavior<FrameLayout> behavior2 = getBehavior();
            behavior2.T(3);
            behavior2.S(true);
            behavior2.N(true);
            behavior2.Q((int) (((Number) t.E(getScreen().getSheetDetents())).doubleValue() * r0.intValue()));
            return;
        }
        if (size == 2) {
            BottomSheetBehavior<FrameLayout> behavior3 = getBehavior();
            behavior3.T(SheetUtils.INSTANCE.sheetStateFromDetentIndex(getScreen().getSheetInitialDetentIndex(), getScreen().getSheetDetents().size()));
            behavior3.S(false);
            behavior3.N(true);
            behavior3.R((int) (getScreen().getSheetDetents().get(0).doubleValue() * r0.intValue()));
            behavior3.Q((int) (getScreen().getSheetDetents().get(1).doubleValue() * r0.intValue()));
            return;
        }
        if (size != 3) {
            throw new IllegalStateException(a.h(getScreen().getSheetDetents().size(), "[RNScreens] Invalid detent count ", ". Expected at most 3."));
        }
        BottomSheetBehavior<FrameLayout> behavior4 = getBehavior();
        behavior4.T(SheetUtils.INSTANCE.sheetStateFromDetentIndex(getScreen().getSheetInitialDetentIndex(), getScreen().getSheetDetents().size()));
        behavior4.S(false);
        behavior4.N(false);
        behavior4.R((int) (getScreen().getSheetDetents().get(0).doubleValue() * r0.intValue()));
        behavior4.M((int) ((1 - getScreen().getSheetDetents().get(2).doubleValue()) * r0.intValue()));
        behavior4.O((float) (getScreen().getSheetDetents().get(1).doubleValue() / getScreen().getSheetDetents().get(2).doubleValue()));
    }

    private final j configureDialogAndBehaviour() {
        Context requireContext = requireContext();
        r.j(requireContext, "requireContext(...)");
        BottomSheetDialogScreen bottomSheetDialogScreen = new BottomSheetDialogScreen(requireContext, this);
        this.sheetDialog = bottomSheetDialogScreen;
        bottomSheetDialogScreen.setDismissWithAnimation(true);
        j jVar = this.sheetDialog;
        if (jVar == null) {
            r.o("sheetDialog");
            throw null;
        }
        jVar.setCanceledOnTouchOutside(getScreen().getSheetClosesOnTouchOutside());
        configureBehaviour();
        j jVar2 = this.sheetDialog;
        if (jVar2 != null) {
            return jVar2;
        }
        r.o("sheetDialog");
        throw null;
    }

    private final BottomSheetBehavior<FrameLayout> getBehavior() {
        j jVar = this.sheetDialog;
        if (jVar == null) {
            r.o("sheetDialog");
            throw null;
        }
        BottomSheetBehavior<FrameLayout> behavior = jVar.getBehavior();
        r.j(behavior, "getBehavior(...)");
        return behavior;
    }

    private final ScreenStack getContainer() {
        ScreenContainer container = getScreen().getContainer();
        if (container instanceof ScreenStack) {
            return (ScreenStack) container;
        }
        return null;
    }

    private final Integer tryResolveContainerHeight() {
        WindowMetrics i;
        Rect g;
        Resources resources;
        DisplayMetrics displayMetrics;
        ScreenContainer container = getScreen().getContainer();
        if (container != null) {
            return Integer.valueOf(container.getHeight());
        }
        Context context = getContext();
        if (context != null && (resources = context.getResources()) != null && (displayMetrics = resources.getDisplayMetrics()) != null) {
            return Integer.valueOf(displayMetrics.heightPixels);
        }
        if (Build.VERSION.SDK_INT >= 30) {
            Context context2 = getContext();
            Object systemService = context2 != null ? context2.getSystemService("window") : null;
            WindowManager windowManager = systemService instanceof WindowManager ? (WindowManager) systemService : null;
            if (windowManager != null && (i = h.i(windowManager)) != null && (g = h.g(i)) != null) {
                return Integer.valueOf(g.height());
            }
        }
        return null;
    }

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

    @Override
    public boolean canDispatchLifecycleEvent(@NotNull ScreenFragment.ScreenLifecycleEvent event) {
        r.k(event, "event");
        throw new zp.r("An operation is not implemented: Not yet implemented");
    }

    @Override
    public boolean canNavigateBack() {
        return true;
    }

    @Override
    public void dismissFromContainer() {
        if (getContainer() == null) {
            throw new IllegalStateException("Check failed.");
        }
        ScreenStack container = getContainer();
        r.i(container, "null cannot be cast to non-null type com.swmansion.rnscreens.ScreenStack");
        container.dismiss(this);
    }

    @Override
    public void dispatchHeaderBackButtonClickedEvent() {
        throw new zp.r("An operation is not implemented: Not yet implemented");
    }

    @Override
    public void dispatchLifecycleEvent(@NotNull ScreenFragment.ScreenLifecycleEvent event, @NotNull ScreenFragmentWrapper fragmentWrapper) {
        r.k(event, "event");
        r.k(fragmentWrapper, "fragmentWrapper");
        throw new zp.r("An operation is not implemented: Not yet implemented");
    }

    @Override
    public void dispatchLifecycleEventInChildContainers(@NotNull ScreenFragment.ScreenLifecycleEvent event) {
        r.k(event, "event");
        throw new zp.r("An operation is not implemented: Not yet implemented");
    }

    @Override
    public void dispatchTransitionProgressEvent(float alpha, boolean closing) {
        throw new zp.r("An operation is not implemented: Not yet implemented");
    }

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

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

    @Override
    public void onContainerUpdate() {
    }

    public void onCreate(@Nullable Bundle savedInstanceState) {
        super/*androidx.fragment.app.n*/.onCreate(savedInstanceState);
        setShowsDialog(true);
    }

    @NotNull
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        configureDialogAndBehaviour();
        EventDispatcher reactEventDispatcher = getScreen().getReactEventDispatcher();
        if (reactEventDispatcher == null) {
            throw new IllegalStateException("[RNScreens] No ReactEventDispatcher attached to screen while creating modal fragment");
        }
        RootView bottomSheetDialogRootView = new BottomSheetDialogRootView(getScreen().getReactContext(), reactEventDispatcher);
        bottomSheetDialogRootView.addView(ViewExtKt.recycle(getScreen()));
        j jVar = this.sheetDialog;
        if (jVar == null) {
            r.o("sheetDialog");
            throw null;
        }
        jVar.setContentView(bottomSheetDialogRootView);
        View parentAsView = ViewExtKt.parentAsView(bottomSheetDialogRootView);
        if (parentAsView != null) {
            parentAsView.setClipToOutline(true);
        }
        j jVar2 = this.sheetDialog;
        if (jVar2 != null) {
            return jVar2;
        }
        r.o("sheetDialog");
        throw null;
    }

    @Nullable
    public View onCreateView(@NotNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        r.k(inflater, "inflater");
        return null;
    }

    public void onDestroy() {
        super/*androidx.fragment.app.p*/.onDestroy();
        ScreenStack container = 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 ScreenDismissedEvent(surfaceId, getScreen().getId()));
                }
            }
        }
        getChildScreenContainers().clear();
    }

    @Override
    public void onViewAnimationEnd() {
    }

    @Override
    public void onViewAnimationStart() {
    }

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

    @Override
    public void removeToolbar() {
        throw new IllegalStateException("[RNScreens] Modal screens on Android do not support header right now");
    }

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

    @Override
    public void setToolbar(@NotNull Toolbar toolbar) {
        r.k(toolbar, "toolbar");
        throw new IllegalStateException("[RNScreens] Modal screens on Android do not support header right now");
    }

    @Override
    public void setToolbarShadowHidden(boolean hidden) {
        throw new IllegalStateException("[RNScreens] Modal screens on Android do not support header right now");
    }

    @Override
    public void setToolbarTranslucent(boolean translucent) {
        throw new IllegalStateException("[RNScreens] Modal screens on Android do not support header right now");
    }

    @Override
    @Nullable
    public Activity tryGetActivity() {
        return requireActivity();
    }

    @Override
    @Nullable
    public ReactContext tryGetContext() {
        if (getContext() instanceof ReactContext) {
            ReactContext context = getContext();
            r.i(context, "null cannot be cast to non-null type com.facebook.react.bridge.ReactContext");
            return context;
        }
        if (getScreen().getContext() instanceof ReactContext) {
            ReactContext context2 = getScreen().getContext();
            r.i(context2, "null cannot be cast to non-null type com.facebook.react.bridge.ReactContext");
            return context2;
        }
        for (ViewParent container = getScreen().getContainer(); container != null; container = container.getParent()) {
            if (container instanceof Screen) {
                Screen screen = (Screen) container;
                if (screen.getContext() instanceof ReactContext) {
                    ReactContext context3 = screen.getContext();
                    r.i(context3, "null cannot be cast to non-null type com.facebook.react.bridge.ReactContext");
                    return context3;
                }
            }
        }
        return null;
    }

    @Override
    public void updateLastEventDispatched(@NotNull ScreenFragment.ScreenLifecycleEvent event) {
        r.k(event, "event");
        throw new zp.r("An operation is not implemented: Not yet implemented");
    }

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

    public ScreenModalFragment(@NotNull Screen screen) {
        r.k(screen, "screen");
        this.childScreenContainers = new ArrayList<>();
        setScreen(screen);
    }
}