Skip to content

Commit

Permalink
处理横竖屏切换,界面可能不销毁的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
listenzz committed Feb 7, 2025
1 parent 0522849 commit 87c9d12
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.facebook.react:react-native:+'
// api project(':navigation')
api 'io.github.listenzz:AndroidNavigation:13.6.9'
api 'io.github.listenzz:AndroidNavigation:13.7.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_DISAPPEAR;
import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_RESULT;

import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Bundle;
Expand Down Expand Up @@ -142,13 +143,13 @@ public void onStart() {
}
}

@SuppressLint("SourceLockedOrientationActivity")
@Override
public void onStop() {
super.onStop();
if (forceScreenLandscape() && isRemoving()) {
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
unmountReactView();
if (isRemoving() && forceScreenLandscape()) {
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
super.onStop();
}

@Override
Expand All @@ -163,14 +164,14 @@ private void mountReactView() {

private void unmountReactView() {
getReactBridgeManager().removeReactBridgeReloadListener(this);

ReactContext reactContext = getCurrentReactContext();
if (reactContext == null || !reactContext.hasActiveCatalystInstance()) {
return;
}

if (reactRootView != null) {
FLog.w(TAG, "销毁页面:" + getModuleName());
FLog.w(TAG, "销毁页面-:" + getModuleName());
reactRootView.unmountReactApplication();
ViewGroup parent = (ViewGroup) reactRootView.getParent();
parent.removeView(reactRootView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void handleShowModalLayout(@NonNull AwesomeFragment presenting, @NonNull
}
presented.setPresentationStyle(PresentationStyle.OverFullScreen);
int requestCode = extras.getInt("requestCode");
presenting.presentFragment(presented, requestCode, () -> callback.invoke(null, true), TransitionAnimation.Fade);
presenting.presentFragment(presented, requestCode, () -> callback.invoke(null, true), TransitionAnimation.None);
}

private void handlePresentLayout(@NonNull AwesomeFragment presenting, @NonNull ReadableMap extras, @NonNull Callback callback) {
Expand Down Expand Up @@ -164,11 +164,11 @@ private void handleShowModal(@NonNull AwesomeFragment presenting, @NonNull Reada
presented.setPresentationStyle(PresentationStyle.OverFullScreen);
int requestCode = extras.getInt("requestCode");

presenting.presentFragment(presented, requestCode, () -> callback.invoke(null, true), TransitionAnimation.Fade);
presenting.presentFragment(presented, requestCode, () -> callback.invoke(null, true), TransitionAnimation.None);
}

private void handleHideModal(@NonNull AwesomeFragment presented, @NonNull Callback callback) {
presented.dismissFragment(() -> callback.invoke(null, true), TransitionAnimation.Fade);
presented.dismissFragment(() -> callback.invoke(null, true), TransitionAnimation.None);
}

private void handleDismiss(@NonNull AwesomeFragment presented, @NonNull Callback callback) {
Expand Down

0 comments on commit 87c9d12

Please sign in to comment.