@@ -78,6 +79,7 @@
:animationType="dialogAnimationType"
:transparent="true"
@requestClose="onClose"
+ @orientationChange="onOrientationChange"
>
{
console.log('Dialog is opening');
};
-
+ const onOrientationChange = (evt) => {
+ console.log('orientation changed', evt.nativeParams);
+ };
const onClose = (evt) => {
evt.stopPropagation();
/**
diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalDialogView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalDialogView.java
new file mode 100644
index 00000000000..75aeb646bca
--- /dev/null
+++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalDialogView.java
@@ -0,0 +1,98 @@
+/* Tencent is pleased to support the open source community by making Hippy available.
+ * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.tencent.mtt.hippy.views.modal;
+
+import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
+import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
+import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
+import static com.tencent.renderer.utils.EventUtils.EVENT_ORIENTATION_CHANGED;
+
+import android.app.Dialog;
+import android.content.ComponentCallbacks;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.view.View;
+import androidx.annotation.NonNull;
+import com.tencent.renderer.utils.EventUtils;
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+
+public class HippyModalDialogView extends Dialog {
+ private int mOrientation = ORIENTATION_UNDEFINED;
+ private final ConfigurationChangedListener mListener = new ConfigurationChangedListener();;
+ private final WeakReference mHostView;
+
+ public HippyModalDialogView(@NonNull Context context, int themeResId, @NonNull View hostView) {
+ super(context, themeResId);
+ mHostView = new WeakReference<>(hostView);
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Configuration configuration = getContext().getResources().getConfiguration();
+ mOrientation = configuration.orientation;
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ getContext().registerComponentCallbacks(mListener);
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ getContext().unregisterComponentCallbacks(mListener);
+ }
+
+ protected void sendOrientationChangeEvent(int orientation) {
+ final View hostView = mHostView.get();
+ if (hostView != null) {
+ String value;
+ switch (orientation) {
+ case ORIENTATION_PORTRAIT:
+ value = "portrait";
+ break;
+ case ORIENTATION_LANDSCAPE:
+ value = "landscape";
+ break;
+ default:
+ value = "";
+ }
+ HashMap params = new HashMap<>();
+ params.put("orientation", value);
+ EventUtils.sendComponentEvent(hostView, EVENT_ORIENTATION_CHANGED, params);
+ }
+ }
+
+ private class ConfigurationChangedListener implements ComponentCallbacks {
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ if (newConfig.orientation != mOrientation) {
+ sendOrientationChangeEvent(newConfig.orientation);
+ mOrientation = newConfig.orientation;
+ }
+ }
+
+ @Override
+ public void onLowMemory() {
+ // Handle low memory event
+ }
+ }
+}
diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java
index e7bb9ef9975..de6e82e72f9 100644
--- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java
+++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java
@@ -70,7 +70,7 @@ public enum AnimationStyleTheme {
@NonNull
private final DialogRootView mDialogRootView;
@Nullable
- private Dialog mDialog;
+ private HippyModalDialogView mDialog;
@Nullable
private View mContentView;
@Nullable
@@ -356,9 +356,9 @@ protected void showOrUpdate() {
}
@NonNull
- protected Dialog createDialog(@NonNull Context context) {
+ protected HippyModalDialogView createDialog(@NonNull Context context) {
int themeResId = android.R.style.Theme_Translucent_NoTitleBar;
- return new Dialog(context, themeResId);
+ return new HippyModalDialogView(context, themeResId, this);
}
@NonNull
diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/utils/EventUtils.java b/renderer/native/android/src/main/java/com/tencent/renderer/utils/EventUtils.java
index a6da91aac85..4b2ff6ee965 100644
--- a/renderer/native/android/src/main/java/com/tencent/renderer/utils/EventUtils.java
+++ b/renderer/native/android/src/main/java/com/tencent/renderer/utils/EventUtils.java
@@ -77,6 +77,8 @@ public class EventUtils {
public static final String EVENT_MODAL_REQUEST_CLOSE = "requestClose";
// On modal view show.
public static final String EVENT_MODAL_SHOW = "show";
+ // On modal orientation changed.
+ public static final String EVENT_ORIENTATION_CHANGED = "orientationChange";
// On refresh wrapper view refresh.
public static final String EVENT_REFRESH_WRAPPER_REFRESH = "refresh";