mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Merge pull request #3390 from NativeScript/issue-1639
Fix: Custom components within other custom components: occasionally n…
This commit is contained in:
4
apps/app/ui-tests-app/issues/component/customView.css
Normal file
4
apps/app/ui-tests-app/issues/component/customView.css
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.local-green {
|
||||||
|
color: green;
|
||||||
|
margin-left: 10;
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
<StackLayout xmlns:cC2="/ui-tests-app/issues/component2">
|
<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" textWrap="true" />
|
<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/>
|
<cC2:customView2/>
|
||||||
</StackLayout>
|
</StackLayout>
|
4
apps/app/ui-tests-app/issues/component2/customView2.css
Normal file
4
apps/app/ui-tests-app/issues/component2/customView2.css
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.local-blue {
|
||||||
|
color: blue;
|
||||||
|
margin-left: 20;
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
<StackLayout xmlns:cC3="/ui-tests-app/issues/component3">
|
<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" textWrap="true" />
|
<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/>
|
<cC3:customView3/>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
4
apps/app/ui-tests-app/issues/component3/customView3.css
Normal file
4
apps/app/ui-tests-app/issues/component3/customView3.css
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.local-yellow {
|
||||||
|
color: yellow;
|
||||||
|
margin-left: 30;
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
<StackLayout>
|
<StackLayout style.borderWidth="1" style.borderColor="black">
|
||||||
<Label class="ui-tests-app-issue-1639-yellow" text="customView3 yellow" textWrap="true" />
|
<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>
|
</StackLayout>
|
||||||
|
4
apps/app/ui-tests-app/issues/issue-1639.css
Normal file
4
apps/app/ui-tests-app/issues/issue-1639.css
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.local-red {
|
||||||
|
color: red;
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:cC="ui-tests-app/issues/component">
|
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:cC="ui-tests-app/issues/component" id="main-page">
|
||||||
<StackLayout>
|
<StackLayout style.borderWidth="1" style.borderColor="black">
|
||||||
<Label class="ui-tests-app-issue-1639-red" text="main-page red" textWrap="true" />
|
<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/>
|
<cC:customView/>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</Page>
|
</Page>
|
@ -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 {
|
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;
|
var result: ComponentModule;
|
||||||
componentPath = componentPath.replace("~/", "");
|
componentPath = componentPath.replace("~/", "");
|
||||||
const moduleName = componentPath + "/" + componentName;
|
const moduleName = componentPath + "/" + componentName;
|
||||||
@ -89,7 +95,14 @@ function loadCustomComponent(componentPath: string, componentName?: string, attr
|
|||||||
subExports = global.loadModule(jsFilePath)
|
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);
|
result = loadInternal(xmlFilePath, subExports);
|
||||||
|
|
||||||
// Attributes will be transfered to the custom component
|
// Attributes will be transfered to the custom component
|
||||||
|
Reference in New Issue
Block a user