From cf2b5b3fac824f9e20c9c63e5880892dfda180df Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 4 Sep 2020 15:04:55 +0800 Subject: [PATCH] feat:Popover area do not over the root view's area --- .../java/pub/doric/plugin/PopoverPlugin.java | 34 ++++- doric-demo/src/PopoverDemo.ts | 131 ++++++++++++------ .../Pod/Classes/Plugin/DoricPopoverPlugin.m | 5 +- 3 files changed, 127 insertions(+), 43 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java b/doric-android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java index 4f347bd7..4a6201af 100644 --- a/doric-android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java +++ b/doric-android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java @@ -1,5 +1,6 @@ package pub.doric.plugin; +import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; @@ -7,6 +8,7 @@ import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; import com.github.pengfeizhou.jscore.JavaValue; +import com.qmuiteam.qmui.util.QMUIDisplayHelper; import java.util.concurrent.Callable; @@ -40,11 +42,37 @@ public class PopoverPlugin extends DoricJavaPlugin { getDoricContext().getDriver().asyncCall(new Callable() { @Override public Object call() throws Exception { + ViewGroup decorView = (ViewGroup) getDoricContext().getRootNode().getNodeView().getRootView(); if (mFullScreenView == null) { mFullScreenView = new FrameLayout(getDoricContext().getContext()); - ViewGroup decorView = (ViewGroup) getDoricContext().getRootNode().getNodeView().getRootView(); - decorView.addView(mFullScreenView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT)); + View navBar = (View) getDoricContext().getDoricNavBar(); + ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT); + int marginTop = 0; + if (navBar != null && navBar.getVisibility() == View.VISIBLE) { + int[] navBarLocation = new int[2]; + navBar.getLocationOnScreen(navBarLocation); + int[] decorViewLocation = new int[2]; + decorView.getLocationOnScreen(decorViewLocation); + marginTop = navBarLocation[1] - decorViewLocation[1] + navBar.getHeight(); + } + layoutParams.topMargin = marginTop; + layoutParams.bottomMargin = QMUIDisplayHelper.getNavMenuHeight(getDoricContext().getContext()); + decorView.addView(mFullScreenView, layoutParams); + } else { + ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) mFullScreenView.getLayoutParams(); + View navBar = (View) getDoricContext().getDoricNavBar(); + int marginTop = 0; + if (navBar != null && navBar.getVisibility() == View.VISIBLE) { + int[] navBarLocation = new int[2]; + navBar.getLocationOnScreen(navBarLocation); + int[] decorViewLocation = new int[2]; + decorView.getLocationOnScreen(decorViewLocation); + marginTop = navBarLocation[1] - decorViewLocation[1] + navBar.getHeight(); + } + layoutParams.topMargin = marginTop; + layoutParams.bottomMargin = QMUIDisplayHelper.getNavMenuHeight(getDoricContext().getContext()); + mFullScreenView.setLayoutParams(layoutParams); } mFullScreenView.bringToFront(); String viewId = jsObject.getProperty("id").asString().value(); diff --git a/doric-demo/src/PopoverDemo.ts b/doric-demo/src/PopoverDemo.ts index d0b3097e..7190eeab 100644 --- a/doric-demo/src/PopoverDemo.ts +++ b/doric-demo/src/PopoverDemo.ts @@ -1,44 +1,97 @@ -import { Group, Panel, popover, text, gravity, Color, LayoutSpec, vlayout, Gravity, scroller, layoutConfig, modal, } from "doric"; +import { + stack, + Group, + Panel, + popover, + text, + gravity, + Color, + LayoutSpec, + vlayout, + Gravity, + scroller, + layoutConfig, + modal, + navbar, +} from "doric"; import { title, label, colors } from "./utils"; @Entry class PopoverDemo extends Panel { - build(rootView: Group): void { - scroller(vlayout([ - title("Popover Demo"), - label('Popover').apply({ - width: 200, - height: 50, - backgroundColor: colors[0], - textSize: 30, - textColor: Color.WHITE, - layoutConfig: layoutConfig().just(), - onClick: () => { - popover(context).show(text({ - width: 200, - height: 50, - backgroundColor: colors[0], - textColor: Color.WHITE, - layoutConfig: layoutConfig().just().configAlignment(Gravity.Center), - text: "This is PopOver Window", - }).also(v => { - let idx = 0 - v.onClick = () => { - v.backgroundColor = colors[(++idx) % colors.length] - } - modal(context).toast('Dismissed after 3 seconds') - setTimeout(() => { - popover(context).dismiss() - }, 3000) - })) + build(rootView: Group): void { + scroller( + vlayout([ + title("Popover Demo"), + label("show navbar").apply({ + width: 200, + height: 50, + backgroundColor: colors[0], + textSize: 30, + textColor: Color.WHITE, + layoutConfig: layoutConfig().just(), + onClick: () => { + navbar(context).setHidden(false); + }, + }), + label("hide navbar").apply({ + width: 200, + height: 50, + backgroundColor: colors[0], + textSize: 30, + textColor: Color.WHITE, + layoutConfig: layoutConfig().just(), + onClick: () => { + navbar(context).setHidden(true); + }, + }), + label("Popover").apply({ + width: 200, + height: 50, + backgroundColor: colors[0], + textSize: 30, + textColor: Color.WHITE, + layoutConfig: layoutConfig().just(), + onClick: () => { + popover(context).show( + stack( + [ + text({ + width: 200, + height: 50, + backgroundColor: colors[0], + textColor: Color.WHITE, + layoutConfig: layoutConfig() + .just() + .configAlignment(Gravity.Center), + text: "This is PopOver Window", + }).also((v) => { + let idx = 0; + v.onClick = () => { + v.backgroundColor = colors[++idx % colors.length]; + }; + modal(context).toast("Dismissed after 3 seconds"); + setTimeout(() => { + popover(context).dismiss(); + }, 3000); + }), + ], + { + layoutConfig: layoutConfig().most(), + backgroundColor: Color.RED.alpha(1), } - }), - ]).apply({ - layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT), - gravity: gravity().center(), - space: 10, - })).apply({ - layoutConfig: layoutConfig().most(), - }).in(rootView) - } -} \ No newline at end of file + ) + ); + }, + }), + ]).apply({ + layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT), + gravity: gravity().center(), + space: 10, + }) + ) + .apply({ + layoutConfig: layoutConfig().most(), + }) + .in(rootView); + } +} diff --git a/doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m index 49468845..fa8f02e8 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m @@ -15,7 +15,7 @@ @implementation DoricPopoverPlugin - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise { dispatch_async(dispatch_get_main_queue(), ^{ - UIView *superView = [UIApplication sharedApplication].windows.lastObject; + UIView *superView = self.doricContext.vc.view; if (!self.fullScreenView) { self.fullScreenView = [[UIView new] also:^(UIView *it) { it.width = superView.width; @@ -24,6 +24,9 @@ - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise { it.doricLayout.layoutType = DoricStack; [superView addSubview:it]; }]; + } else { + self.fullScreenView.doricLayout.width = superView.width; + self.fullScreenView.doricLayout.height = superView.height; } [superView bringSubviewToFront:self.fullScreenView]; self.fullScreenView.hidden = NO;