mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Merge pull request #846 from NativeScript/placeholder-event-fix
placeholder creatingView event fixed + tests
This commit is contained in:
@ -80,6 +80,7 @@
|
|||||||
<DependentUpon>data-binding.xml</DependentUpon>
|
<DependentUpon>data-binding.xml</DependentUpon>
|
||||||
</TypeScriptCompile>
|
</TypeScriptCompile>
|
||||||
<TypeScriptCompile Include="apps\tests\ui\action-bar\ActionBar_NumberAsText.ts" />
|
<TypeScriptCompile Include="apps\tests\ui\action-bar\ActionBar_NumberAsText.ts" />
|
||||||
|
<TypeScriptCompile Include="apps\tests\ui\placeholder\placeholder-tests.ts" />
|
||||||
<TypeScriptCompile Include="apps\tests\xml-declaration\custom-code-file.ts" />
|
<TypeScriptCompile Include="apps\tests\xml-declaration\custom-code-file.ts" />
|
||||||
<TypeScriptCompile Include="apps\transforms\app.ts" />
|
<TypeScriptCompile Include="apps\transforms\app.ts" />
|
||||||
<TypeScriptCompile Include="apps\transforms\main-page.ts" />
|
<TypeScriptCompile Include="apps\transforms\main-page.ts" />
|
||||||
@ -1984,7 +1985,7 @@
|
|||||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||||
</WebProjectProperties>
|
</WebProjectProperties>
|
||||||
</FlavorProperties>
|
</FlavorProperties>
|
||||||
<UserProperties ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" />
|
<UserProperties ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" />
|
||||||
</VisualStudio>
|
</VisualStudio>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
</Project>
|
</Project>
|
@ -61,6 +61,7 @@ allTests["IMAGE"] = require("./ui/image/image-tests");
|
|||||||
allTests["SLIDER"] = require("./ui/slider/slider-tests");
|
allTests["SLIDER"] = require("./ui/slider/slider-tests");
|
||||||
allTests["SWITCH"] = require("./ui/switch/switch-tests");
|
allTests["SWITCH"] = require("./ui/switch/switch-tests");
|
||||||
allTests["PROGRESS"] = require("./ui/progress/progress-tests");
|
allTests["PROGRESS"] = require("./ui/progress/progress-tests");
|
||||||
|
allTests["PLACEHOLDER"] = require("./ui/placeholder/placeholder-tests");
|
||||||
allTests["PAGE"] = require("./ui/page/page-tests");
|
allTests["PAGE"] = require("./ui/page/page-tests");
|
||||||
allTests["LISTVIEW"] = require("./ui/list-view/list-view-tests");
|
allTests["LISTVIEW"] = require("./ui/list-view/list-view-tests");
|
||||||
allTests["ACTIVITY-INDICATOR"] = require("./ui/activity-indicator/activity-indicator-tests");
|
allTests["ACTIVITY-INDICATOR"] = require("./ui/activity-indicator/activity-indicator-tests");
|
||||||
|
78
apps/tests/ui/placeholder/placeholder-tests.ts
Normal file
78
apps/tests/ui/placeholder/placeholder-tests.ts
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import TKUnit = require("../../TKUnit");
|
||||||
|
import platform = require("platform");
|
||||||
|
import utils = require("utils/utils");
|
||||||
|
import helper = require("../helper");
|
||||||
|
import viewModule = require("ui/core/view");
|
||||||
|
|
||||||
|
// <snippet module="ui/placeholder" title="placeholder">
|
||||||
|
// # Placeholder
|
||||||
|
// Using the placeholder requires the Placeholder module.
|
||||||
|
// ``` JavaScript
|
||||||
|
import placeholderModule = require("ui/placeholder");
|
||||||
|
// ```
|
||||||
|
|
||||||
|
// Creating native view for the Placeholder using creatingView event.
|
||||||
|
//```XML
|
||||||
|
// <Page>
|
||||||
|
// {%raw%}<Placeholder creatingView="creatingView" />{%endraw%}
|
||||||
|
// </Page>
|
||||||
|
//```
|
||||||
|
//```JS
|
||||||
|
//var platform = require("platform");
|
||||||
|
//var utils = require("utils/utils");
|
||||||
|
//
|
||||||
|
//function creatingView(args) {
|
||||||
|
// var nativeView;
|
||||||
|
// if (platform.device.os === platform.platformNames.ios) {
|
||||||
|
// nativeView = new UITextView();
|
||||||
|
// nativeView.text = "Native";
|
||||||
|
// } else if (platform.device.os === platform.platformNames.android) {
|
||||||
|
// nativeView = new android.widget.TextView(utils.ad.getApplicationContext());
|
||||||
|
// nativeView.setText("Native");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// args.view = nativeView;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//exports.creatingView = creatingView;
|
||||||
|
//```
|
||||||
|
// </snippet>
|
||||||
|
|
||||||
|
export function test_placeholder_creatingView() {
|
||||||
|
var nativeView;
|
||||||
|
|
||||||
|
var p = new placeholderModule.Placeholder();
|
||||||
|
p.id = "test";
|
||||||
|
p.on(placeholderModule.Placeholder.creatingViewEvent, (args: placeholderModule.CreateViewEventData) => {
|
||||||
|
if (platform.device.os === platform.platformNames.ios) {
|
||||||
|
nativeView = new UITextView();
|
||||||
|
nativeView.text = "Native";
|
||||||
|
} else if (platform.device.os === platform.platformNames.android) {
|
||||||
|
nativeView = new android.widget.TextView(utils.ad.getApplicationContext());
|
||||||
|
nativeView.setText("Native");
|
||||||
|
}
|
||||||
|
|
||||||
|
args.view = nativeView;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (platform.device.os === platform.platformNames.ios) {
|
||||||
|
TKUnit.assert(p.ios instanceof UITextView, "ios property should be UITextView. Current value: " + p.ios);
|
||||||
|
} else if (platform.device.os === platform.platformNames.android) {
|
||||||
|
p._emit("creatingView");
|
||||||
|
TKUnit.assert(nativeView instanceof android.widget.TextView, "Native view should be android.widget.TextView. Current value: " + nativeView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function test_placeholder_will_not_crash_wihout_creatingView() {
|
||||||
|
var p = new placeholderModule.Placeholder();
|
||||||
|
|
||||||
|
function testAction(views: Array<viewModule.View>) {
|
||||||
|
if (platform.device.os === platform.platformNames.ios) {
|
||||||
|
TKUnit.assert(p.ios === undefined, "ios property should be undefined. Current value: " + p.ios);
|
||||||
|
} else if (platform.device.os === platform.platformNames.android) {
|
||||||
|
TKUnit.assert(p.android === undefined, "android view should be undefined. Current value: " + p.android);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
helper.buildUIAndRunTest(p, testAction);
|
||||||
|
}
|
@ -196,8 +196,10 @@ export class View extends viewCommon.View {
|
|||||||
|
|
||||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||||
var view = this._nativeView;
|
var view = this._nativeView;
|
||||||
if (view) {
|
let nativeWidth = 0;
|
||||||
|
let nativeHeight = 0;
|
||||||
|
|
||||||
|
if (view) {
|
||||||
var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
|
var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
|
||||||
var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
|
var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
|
||||||
|
|
||||||
@ -213,16 +215,18 @@ export class View extends viewCommon.View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var nativeSize = view.sizeThatFits(CGSizeMake(width, height));
|
var nativeSize = view.sizeThatFits(CGSizeMake(width, height));
|
||||||
|
nativeWidth = nativeSize.width;
|
||||||
|
nativeHeight = nativeSize.height;
|
||||||
|
}
|
||||||
|
|
||||||
var measureWidth = Math.max(nativeSize.width, this.minWidth);
|
var measureWidth = Math.max(nativeWidth, this.minWidth);
|
||||||
var measureHeight = Math.max(nativeSize.height, this.minHeight);
|
var measureHeight = Math.max(nativeHeight, this.minHeight);
|
||||||
|
|
||||||
var widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
|
var widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
|
||||||
var heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
|
var heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
|
||||||
|
|
||||||
this.setMeasuredDimension(widthAndState, heightAndState);
|
this.setMeasuredDimension(widthAndState, heightAndState);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||||
//
|
//
|
||||||
|
@ -9,7 +9,7 @@ export class Placeholder extends common.Placeholder {
|
|||||||
public _createUI() {
|
public _createUI() {
|
||||||
var args = <definition.CreateViewEventData>{ eventName: common.Placeholder.creatingViewEvent, object: this, view: undefined, context: this._context };
|
var args = <definition.CreateViewEventData>{ eventName: common.Placeholder.creatingViewEvent, object: this, view: undefined, context: this._context };
|
||||||
this.notify(args);
|
this.notify(args);
|
||||||
this._android = <android.view.View>args.view || new android.view.View(this._context);
|
this._android = <android.view.View>args.view;
|
||||||
}
|
}
|
||||||
|
|
||||||
get android(): android.view.View {
|
get android(): android.view.View {
|
||||||
|
@ -10,7 +10,7 @@ export class Placeholder extends common.Placeholder {
|
|||||||
if (!this._ios) {
|
if (!this._ios) {
|
||||||
var args = <definition.CreateViewEventData>{ eventName: common.Placeholder.creatingViewEvent, object: this, view: undefined, context: undefined };
|
var args = <definition.CreateViewEventData>{ eventName: common.Placeholder.creatingViewEvent, object: this, view: undefined, context: undefined };
|
||||||
super.notify(args);
|
super.notify(args);
|
||||||
this._ios = args.view || new UIView();
|
this._ios = args.view;
|
||||||
}
|
}
|
||||||
return this._ios;
|
return this._ios;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user