mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +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>
|
||||
</TypeScriptCompile>
|
||||
<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\transforms\app.ts" />
|
||||
<TypeScriptCompile Include="apps\transforms\main-page.ts" />
|
||||
@ -183,8 +184,8 @@
|
||||
<Content Include="apps\tests\pages\tab-view.xml" />
|
||||
<Content Include="apps\ui-tests-app\app.css" />
|
||||
<TypeScriptCompile Include="apps\ui-tests-app\nordic\nordic.ts">
|
||||
<DependentUpon>nordic.xml</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<DependentUpon>nordic.xml</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="apps\ui-tests-app\pages\handlers.ts" />
|
||||
<TypeScriptCompile Include="apps\ui-tests-app\pages\htmlview.ts" />
|
||||
<TypeScriptCompile Include="ui\animation\animation.d.ts" />
|
||||
@ -1984,7 +1985,7 @@
|
||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||
</WebProjectProperties>
|
||||
</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>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
@ -61,6 +61,7 @@ allTests["IMAGE"] = require("./ui/image/image-tests");
|
||||
allTests["SLIDER"] = require("./ui/slider/slider-tests");
|
||||
allTests["SWITCH"] = require("./ui/switch/switch-tests");
|
||||
allTests["PROGRESS"] = require("./ui/progress/progress-tests");
|
||||
allTests["PLACEHOLDER"] = require("./ui/placeholder/placeholder-tests");
|
||||
allTests["PAGE"] = require("./ui/page/page-tests");
|
||||
allTests["LISTVIEW"] = require("./ui/list-view/list-view-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 {
|
||||
var view = this._nativeView;
|
||||
if (view) {
|
||||
let nativeWidth = 0;
|
||||
let nativeHeight = 0;
|
||||
|
||||
if (view) {
|
||||
var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
|
||||
var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
|
||||
|
||||
@ -213,15 +215,17 @@ export class View extends viewCommon.View {
|
||||
}
|
||||
|
||||
var nativeSize = view.sizeThatFits(CGSizeMake(width, height));
|
||||
|
||||
var measureWidth = Math.max(nativeSize.width, this.minWidth);
|
||||
var measureHeight = Math.max(nativeSize.height, this.minHeight);
|
||||
|
||||
var widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
|
||||
var heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
|
||||
|
||||
this.setMeasuredDimension(widthAndState, heightAndState);
|
||||
nativeWidth = nativeSize.width;
|
||||
nativeHeight = nativeSize.height;
|
||||
}
|
||||
|
||||
var measureWidth = Math.max(nativeWidth, this.minWidth);
|
||||
var measureHeight = Math.max(nativeHeight, this.minHeight);
|
||||
|
||||
var widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
|
||||
var heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
|
||||
|
||||
this.setMeasuredDimension(widthAndState, heightAndState);
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
@ -305,12 +309,12 @@ export class CustomLayoutView extends View {
|
||||
|
||||
if (this._nativeView && child._nativeView) {
|
||||
if (types.isNullOrUndefined(atIndex) || atIndex >= this._nativeView.subviews.count) {
|
||||
this._nativeView.addSubview(child._nativeView);
|
||||
this._nativeView.addSubview(child._nativeView);
|
||||
}
|
||||
else {
|
||||
this._nativeView.insertSubviewAtIndex(child._nativeView, atIndex);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ export class Placeholder extends common.Placeholder {
|
||||
public _createUI() {
|
||||
var args = <definition.CreateViewEventData>{ eventName: common.Placeholder.creatingViewEvent, object: this, view: undefined, context: this._context };
|
||||
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 {
|
||||
|
@ -10,7 +10,7 @@ export class Placeholder extends common.Placeholder {
|
||||
if (!this._ios) {
|
||||
var args = <definition.CreateViewEventData>{ eventName: common.Placeholder.creatingViewEvent, object: this, view: undefined, context: undefined };
|
||||
super.notify(args);
|
||||
this._ios = args.view || new UIView();
|
||||
this._ios = args.view;
|
||||
}
|
||||
return this._ios;
|
||||
}
|
||||
|
Reference in New Issue
Block a user