Merge pull request #3390 from NativeScript/issue-1639

Fix: Custom components within other custom components: occasionally n…
This commit is contained in:
Rossen Hristov
2017-01-03 11:06:55 +02:00
committed by GitHub
9 changed files with 43 additions and 10 deletions

View File

@ -0,0 +1,4 @@
.local-green {
color: green;
margin-left: 10;
}

View File

@ -1,4 +1,5 @@
<StackLayout xmlns:cC2="/ui-tests-app/issues/component2">
<Label class="ui-tests-app-issue-1639-green" text="customView green" textWrap="true" />
<StackLayout xmlns:cC2="/ui-tests-app/issues/component2" style.borderWidth="1" style.borderColor="black">
<Label class="ui-tests-app-issue-1639-green" text="customView green from app.css" textWrap="true" />
<Label class="local-green" text="customView green from customView.css" textWrap="true" />
<cC2:customView2/>
</StackLayout>

View File

@ -0,0 +1,4 @@
.local-blue {
color: blue;
margin-left: 20;
}

View File

@ -1,4 +1,5 @@
<StackLayout xmlns:cC3="/ui-tests-app/issues/component3">
<Label class="ui-tests-app-issue-1639-blue" text="customView2 blue" textWrap="true" />
<StackLayout xmlns:cC3="/ui-tests-app/issues/component3" style.borderWidth="1" style.borderColor="black">
<Label class="ui-tests-app-issue-1639-blue" text="customView2 blue from app.css" textWrap="true" />
<Label class="local-blue" text="customView2 blue from customView2.css" textWrap="true" />
<cC3:customView3/>
</StackLayout>

View File

@ -0,0 +1,4 @@
.local-yellow {
color: yellow;
margin-left: 30;
}

View File

@ -1,3 +1,4 @@
<StackLayout>
<Label class="ui-tests-app-issue-1639-yellow" text="customView3 yellow" textWrap="true" />
<StackLayout style.borderWidth="1" style.borderColor="black">
<Label class="ui-tests-app-issue-1639-yellow" text="customView3 yellow from app.css" textWrap="true" />
<Label class="local-yellow" text="customView3 yellow from customView3.css" textWrap="true" />
</StackLayout>

View File

@ -0,0 +1,4 @@
.local-red {
color: red;
margin-left: 0;
}

View File

@ -1,6 +1,7 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:cC="ui-tests-app/issues/component">
<StackLayout>
<Label class="ui-tests-app-issue-1639-red" text="main-page red" textWrap="true" />
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:cC="ui-tests-app/issues/component" id="main-page">
<StackLayout style.borderWidth="1" style.borderColor="black">
<Label class="ui-tests-app-issue-1639-red" text="main-page red from app.css" textWrap="true" />
<Label class="local-red" text="main-page red from issue-1639.css" textWrap="true" />
<cC:customView/>
</StackLayout>
</Page>

View File

@ -63,6 +63,12 @@ function parseInternal(value: string, context: any, uri?: string): ComponentModu
}
function loadCustomComponent(componentPath: string, componentName?: string, attributes?: Object, context?: Object, parentPage?: Page): ComponentModule {
if (!parentPage && context){
// Read the parent page that was passed down below
// https://github.com/NativeScript/NativeScript/issues/1639
parentPage = context["_parentPage"];
delete context["_parentPage"];
}
var result: ComponentModule;
componentPath = componentPath.replace("~/", "");
const moduleName = componentPath + "/" + componentName;
@ -89,7 +95,14 @@ function loadCustomComponent(componentPath: string, componentName?: string, attr
subExports = global.loadModule(jsFilePath)
}
}
// Pass the parent page down the chain in case of custom components nested on many levels. Use the context for piggybacking.
// https://github.com/NativeScript/NativeScript/issues/1639
if (!subExports) {
subExports = {};
}
subExports["_parentPage"] = parentPage;
result = loadInternal(xmlFilePath, subExports);
// Attributes will be transfered to the custom component