feat:Popover area do not over the root view's area
This commit is contained in:
parent
a8cbdc0c1d
commit
cf2b5b3fac
@ -1,5 +1,6 @@
|
|||||||
package pub.doric.plugin;
|
package pub.doric.plugin;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.FrameLayout;
|
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.JSObject;
|
||||||
import com.github.pengfeizhou.jscore.JSValue;
|
import com.github.pengfeizhou.jscore.JSValue;
|
||||||
import com.github.pengfeizhou.jscore.JavaValue;
|
import com.github.pengfeizhou.jscore.JavaValue;
|
||||||
|
import com.qmuiteam.qmui.util.QMUIDisplayHelper;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
@ -40,11 +42,37 @@ public class PopoverPlugin extends DoricJavaPlugin {
|
|||||||
getDoricContext().getDriver().asyncCall(new Callable<Object>() {
|
getDoricContext().getDriver().asyncCall(new Callable<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public Object call() throws Exception {
|
public Object call() throws Exception {
|
||||||
|
ViewGroup decorView = (ViewGroup) getDoricContext().getRootNode().getNodeView().getRootView();
|
||||||
if (mFullScreenView == null) {
|
if (mFullScreenView == null) {
|
||||||
mFullScreenView = new FrameLayout(getDoricContext().getContext());
|
mFullScreenView = new FrameLayout(getDoricContext().getContext());
|
||||||
ViewGroup decorView = (ViewGroup) getDoricContext().getRootNode().getNodeView().getRootView();
|
View navBar = (View) getDoricContext().getDoricNavBar();
|
||||||
decorView.addView(mFullScreenView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
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();
|
mFullScreenView.bringToFront();
|
||||||
String viewId = jsObject.getProperty("id").asString().value();
|
String viewId = jsObject.getProperty("id").asString().value();
|
||||||
|
@ -1,12 +1,28 @@
|
|||||||
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";
|
import { title, label, colors } from "./utils";
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
class PopoverDemo extends Panel {
|
class PopoverDemo extends Panel {
|
||||||
build(rootView: Group): void {
|
build(rootView: Group): void {
|
||||||
scroller(vlayout([
|
scroller(
|
||||||
|
vlayout([
|
||||||
title("Popover Demo"),
|
title("Popover Demo"),
|
||||||
label('Popover').apply({
|
label("show navbar").apply({
|
||||||
width: 200,
|
width: 200,
|
||||||
height: 50,
|
height: 50,
|
||||||
backgroundColor: colors[0],
|
backgroundColor: colors[0],
|
||||||
@ -14,31 +30,68 @@ class PopoverDemo extends Panel {
|
|||||||
textColor: Color.WHITE,
|
textColor: Color.WHITE,
|
||||||
layoutConfig: layoutConfig().just(),
|
layoutConfig: layoutConfig().just(),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
popover(context).show(text({
|
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,
|
width: 200,
|
||||||
height: 50,
|
height: 50,
|
||||||
backgroundColor: colors[0],
|
backgroundColor: colors[0],
|
||||||
textColor: Color.WHITE,
|
textColor: Color.WHITE,
|
||||||
layoutConfig: layoutConfig().just().configAlignment(Gravity.Center),
|
layoutConfig: layoutConfig()
|
||||||
|
.just()
|
||||||
|
.configAlignment(Gravity.Center),
|
||||||
text: "This is PopOver Window",
|
text: "This is PopOver Window",
|
||||||
}).also(v => {
|
}).also((v) => {
|
||||||
let idx = 0
|
let idx = 0;
|
||||||
v.onClick = () => {
|
v.onClick = () => {
|
||||||
v.backgroundColor = colors[(++idx) % colors.length]
|
v.backgroundColor = colors[++idx % colors.length];
|
||||||
}
|
};
|
||||||
modal(context).toast('Dismissed after 3 seconds')
|
modal(context).toast("Dismissed after 3 seconds");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
popover(context).dismiss()
|
popover(context).dismiss();
|
||||||
}, 3000)
|
}, 3000);
|
||||||
}))
|
}),
|
||||||
|
],
|
||||||
|
{
|
||||||
|
layoutConfig: layoutConfig().most(),
|
||||||
|
backgroundColor: Color.RED.alpha(1),
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
]).apply({
|
]).apply({
|
||||||
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT),
|
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT),
|
||||||
gravity: gravity().center(),
|
gravity: gravity().center(),
|
||||||
space: 10,
|
space: 10,
|
||||||
})).apply({
|
})
|
||||||
|
)
|
||||||
|
.apply({
|
||||||
layoutConfig: layoutConfig().most(),
|
layoutConfig: layoutConfig().most(),
|
||||||
}).in(rootView)
|
})
|
||||||
|
.in(rootView);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,7 +15,7 @@ @implementation DoricPopoverPlugin
|
|||||||
|
|
||||||
- (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
- (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
UIView *superView = [UIApplication sharedApplication].windows.lastObject;
|
UIView *superView = self.doricContext.vc.view;
|
||||||
if (!self.fullScreenView) {
|
if (!self.fullScreenView) {
|
||||||
self.fullScreenView = [[UIView new] also:^(UIView *it) {
|
self.fullScreenView = [[UIView new] also:^(UIView *it) {
|
||||||
it.width = superView.width;
|
it.width = superView.width;
|
||||||
@ -24,6 +24,9 @@ - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
|||||||
it.doricLayout.layoutType = DoricStack;
|
it.doricLayout.layoutType = DoricStack;
|
||||||
[superView addSubview:it];
|
[superView addSubview:it];
|
||||||
}];
|
}];
|
||||||
|
} else {
|
||||||
|
self.fullScreenView.doricLayout.width = superView.width;
|
||||||
|
self.fullScreenView.doricLayout.height = superView.height;
|
||||||
}
|
}
|
||||||
[superView bringSubviewToFront:self.fullScreenView];
|
[superView bringSubviewToFront:self.fullScreenView];
|
||||||
self.fullScreenView.hidden = NO;
|
self.fullScreenView.hidden = NO;
|
||||||
|
Reference in New Issue
Block a user