diff --git a/doric-android/doric/src/main/java/pub/doric/DoricRegistry.java b/doric-android/doric/src/main/java/pub/doric/DoricRegistry.java index 77442ebb..629fc5bf 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricRegistry.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricRegistry.java @@ -31,6 +31,7 @@ import pub.doric.plugin.ModalPlugin; import pub.doric.plugin.NavBarPlugin; import pub.doric.plugin.NavigatorPlugin; import pub.doric.plugin.NetworkPlugin; +import pub.doric.plugin.NotchPlugin; import pub.doric.plugin.NotificationPlugin; import pub.doric.plugin.PopoverPlugin; import pub.doric.plugin.ShaderPlugin; @@ -99,6 +100,7 @@ public class DoricRegistry { this.registerNativePlugin(NotificationPlugin.class); this.registerNativePlugin(StatusBarPlugin.class); this.registerNativePlugin(CoordinatorPlugin.class); + this.registerNativePlugin(NotchPlugin.class); this.registerViewNode(RootNode.class); this.registerViewNode(TextNode.class); diff --git a/doric-android/doric/src/main/java/pub/doric/plugin/NotchPlugin.java b/doric-android/doric/src/main/java/pub/doric/plugin/NotchPlugin.java new file mode 100644 index 00000000..11cacc3e --- /dev/null +++ b/doric-android/doric/src/main/java/pub/doric/plugin/NotchPlugin.java @@ -0,0 +1,36 @@ +package pub.doric.plugin; + +import android.view.View; + +import com.github.pengfeizhou.jscore.JSONBuilder; +import com.github.pengfeizhou.jscore.JSObject; +import com.github.pengfeizhou.jscore.JavaValue; +import com.qmuiteam.qmui.util.QMUINotchHelper; + +import pub.doric.DoricContext; +import pub.doric.extension.bridge.DoricMethod; +import pub.doric.extension.bridge.DoricPlugin; +import pub.doric.extension.bridge.DoricPromise; +import pub.doric.utils.ThreadMode; + +@DoricPlugin(name = "notch") +public class NotchPlugin extends DoricJavaPlugin { + + public NotchPlugin(DoricContext doricContext) { + super(doricContext); + } + + @DoricMethod(thread = ThreadMode.UI) + public void inset(JSObject jsObject, final DoricPromise promise) { + View view = getDoricContext().getRootNode().getNodeView(); + int top = QMUINotchHelper.getSafeInsetTop(view); + int left = QMUINotchHelper.getSafeInsetLeft(view); + int bottom = QMUINotchHelper.getSafeInsetBottom(view); + int right = QMUINotchHelper.getSafeInsetRight(view); + promise.resolve(new JavaValue(new JSONBuilder() + .put("top", top) + .put("left", left) + .put("bottom", bottom) + .put("right", right).toJSONObject())); + } +}