fix: cannot set w and h on root element of ui;

fix: ui.post
This commit is contained in:
hyb1996
2018-09-27 00:22:41 +08:00
parent 00e687f10d
commit dcc09c4034
4 changed files with 11 additions and 8 deletions

View File

@@ -19,7 +19,7 @@ module.exports = function (runtime, global) {
xml = xml.toXMLString();
}
runtime.ui.layoutInflater.setContext(activity);
var view = runtime.ui.layoutInflater.inflate(xml);
var view = runtime.ui.layoutInflater.inflate(xml, activity.window.decorView, false);
ui.setContentView(view);
}
@@ -80,7 +80,7 @@ module.exports = function (runtime, global) {
ui.post = function (action, delay) {
delay = delay || 0;
runtime.getUiHandler().postDelay(wrapUiAction(action), delay);
runtime.getUiHandler().postDelayed(wrapUiAction(action), delay);
}
ui.statusBarColor = function (color) {

View File

@@ -146,20 +146,24 @@ public class DynamicLayoutInflater {
}
public View inflate(String xml, @Nullable ViewGroup parent) {
return inflate(xml, parent, parent != null);
}
public View inflate(String xml, @Nullable ViewGroup parent, boolean attachToParent) {
View view = mLayoutInflaterDelegate.beforeInflation(xml, parent);
if (view != null)
return view;
xml = convertXml(xml);
return mLayoutInflaterDelegate.afterInflation(doInflation(xml, parent), xml, parent);
return mLayoutInflaterDelegate.afterInflation(doInflation(xml, parent, attachToParent), xml, parent);
}
protected View doInflation(String xml, @Nullable ViewGroup parent) {
protected View doInflation(String xml, @Nullable ViewGroup parent, boolean attachToParent) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new ByteArrayInputStream(xml.getBytes()));
return inflate(document.getDocumentElement(), parent, true);
return inflate(document.getDocumentElement(), parent, attachToParent);
} catch (Exception e) {
throw new InflateException(e);
}