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;
|
||||
|
||||
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<Object>() {
|
||||
@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();
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
},
|
||||
}),
|
||||
]).apply({
|
||||
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT),
|
||||
gravity: gravity().center(),
|
||||
space: 10,
|
||||
})
|
||||
)
|
||||
.apply({
|
||||
layoutConfig: layoutConfig().most(),
|
||||
})
|
||||
.in(rootView);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user