| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,6 +89,7 @@ | |||
| 89 | 89 | <DependentUpon>modal-page.xml</DependentUpon> | |
| 90 | 90 | </TypeScriptCompile> | |
| 91 | 91 | <TypeScriptCompile Include="apps\tests\ui\placeholder\placeholder-tests.ts" /> | |
| 92 | + <TypeScriptCompile Include="apps\tests\ui\proxy-view-container\proxy-view-container-tests.ts" /> | ||
| 92 | 93 | <TypeScriptCompile Include="apps\tests\ui\tab-view\tab-view-navigation-tests.ts" /> | |
| 93 | 94 | <TypeScriptCompile Include="apps\tests\xml-declaration\custom-code-file.ts" /> | |
| 94 | 95 | <TypeScriptCompile Include="apps\transforms\app.ts" /> | |
@@ -726,6 +727,8 @@ | |||
| 726 | 727 | <TypeScriptCompile Include="ui\builder\binding-builder.d.ts" /> | |
| 727 | 728 | <TypeScriptCompile Include="ui\builder\special-properties.d.ts" /> | |
| 728 | 729 | <TypeScriptCompile Include="ui\builder\special-properties.ts" /> | |
| 730 | + <TypeScriptCompile Include="ui\proxy-view-container\proxy-view-container.d.ts" /> | ||
| 731 | + <TypeScriptCompile Include="ui\proxy-view-container\proxy-view-container.ts" /> | ||
| 729 | 732 | <TypeScriptCompile Include="ui\styling\background.android.d.ts" /> | |
| 730 | 733 | <TypeScriptCompile Include="ui\styling\style-scope.d.ts" /> | |
| 731 | 734 | <TypeScriptCompile Include="ui\styling\style.d.ts" /> | |
@@ -2087,6 +2090,7 @@ | |||
| 2087 | 2090 | </Content> | |
| 2088 | 2091 | <Content Include="ui\package.json" /> | |
| 2089 | 2092 | <Content Include="tsconfig.json" /> | |
| 2093 | + <Content Include="ui\proxy-view-container\package.json" /> | ||
| 2090 | 2094 | </ItemGroup> | |
| 2091 | 2095 | <ItemGroup> | |
| 2092 | 2096 | <None Include="build\tslint.json" /> | |
@@ -2149,7 +2153,7 @@ | |||
| 2149 | 2153 | <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> | |
| 2150 | 2154 | </WebProjectProperties> | |
| 2151 | 2155 | </FlavorProperties> | |
| 2152 | - <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" /> | ||
| 2156 | + <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" /> | ||
| 2153 | 2157 | </VisualStudio> | |
| 2154 | 2158 | </ProjectExtensions> | |
| 2155 | 2159 | </Project> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ export function isRunningOnEmulator(): boolean { | |||
| 25 | 25 | } | |
| 26 | 26 | ||
| 27 | 27 | export var allTests = {}; | |
| 28 | + allTests["PROXY-VIEW-CONTAINER"] = require("./ui/proxy-view-container/proxy-view-container-tests") | ||
| 28 | 29 | allTests["SCROLL-VIEW"] = require("./ui/scroll-view/scroll-view-tests"); | |
| 29 | 30 | allTests["ACTION-BAR"] = require("./ui/action-bar/action-bar-tests"); | |
| 30 | 31 | allTests["XML-DECLARATION"] = require("./xml-declaration/xml-declaration-tests"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,160 @@ | |||
| 1 | + import TKUnit = require("../../TKUnit"); | ||
| 2 | + import helper = require("../helper"); | ||
| 3 | + import viewModule = require("ui/core/view"); | ||
| 4 | + import observable = require("data/observable"); | ||
| 5 | + import color = require("color"); | ||
| 6 | + import platform = require("platform"); | ||
| 7 | + | ||
| 8 | + import {ProxyViewContainer} from "ui/proxy-view-container"; | ||
| 9 | + import {View, Button, StackLayout} from "ui"; | ||
| 10 | + | ||
| 11 | + export function test_add_children_to_attached_proxy() { | ||
| 12 | + var outer = new StackLayout(); | ||
| 13 | + var proxy = new ProxyViewContainer(); | ||
| 14 | + | ||
| 15 | + function testAction(views: Array<viewModule.View>) { | ||
| 16 | + outer.addChild(createBtn("1")); | ||
| 17 | + outer.addChild(proxy); | ||
| 18 | + proxy.addChild(createBtn("2")); | ||
| 19 | + proxy.addChild(createBtn("3")); | ||
| 20 | + proxy.addChild(createBtn("4")); | ||
| 21 | + | ||
| 22 | + outer.addChild(createBtn("5")); | ||
| 23 | + | ||
| 24 | + assertNativeChildren(outer, ["1", "2", "3", "4", "5"]); | ||
| 25 | + }; | ||
| 26 | + | ||
| 27 | + helper.buildUIAndRunTest(outer, testAction); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + export function test_add_children_to_detached_proxy() { | ||
| 31 | + var outer = new StackLayout(); | ||
| 32 | + var proxy = new ProxyViewContainer(); | ||
| 33 | + | ||
| 34 | + function testAction(views: Array<viewModule.View>) { | ||
| 35 | + outer.addChild(createBtn("1")); | ||
| 36 | + | ||
| 37 | + proxy.addChild(createBtn("2")); | ||
| 38 | + proxy.addChild(createBtn("3")); | ||
| 39 | + proxy.addChild(createBtn("4")); | ||
| 40 | + outer.addChild(proxy); | ||
| 41 | + | ||
| 42 | + outer.addChild(createBtn("5")); | ||
| 43 | + | ||
| 44 | + assertNativeChildren(outer, ["1", "2", "3", "4", "5"]); | ||
| 45 | + }; | ||
| 46 | + | ||
| 47 | + helper.buildUIAndRunTest(outer, testAction); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + export function test_remove_proxy() { | ||
| 51 | + var outer = new StackLayout(); | ||
| 52 | + var proxy = new ProxyViewContainer(); | ||
| 53 | + | ||
| 54 | + outer.addChild(createBtn("1")); | ||
| 55 | + | ||
| 56 | + outer.addChild(proxy); | ||
| 57 | + proxy.addChild(createBtn("2")); | ||
| 58 | + proxy.addChild(createBtn("3")); | ||
| 59 | + proxy.addChild(createBtn("4")); | ||
| 60 | + | ||
| 61 | + outer.addChild(createBtn("5")); | ||
| 62 | + | ||
| 63 | + function testAction(views: Array<viewModule.View>) { | ||
| 64 | + assertNativeChildren(outer, ["1", "2", "3", "4", "5"]); | ||
| 65 | + outer.removeChild(proxy); | ||
| 66 | + assertNativeChildren(outer, ["1", "5"]); | ||
| 67 | + }; | ||
| 68 | + | ||
| 69 | + helper.buildUIAndRunTest(outer, testAction); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + export function test_remove_child_of_attached_proxy() { | ||
| 73 | + var outer = new StackLayout(); | ||
| 74 | + var proxy = new ProxyViewContainer(); | ||
| 75 | + | ||
| 76 | + outer.addChild(createBtn("1")); | ||
| 77 | + | ||
| 78 | + outer.addChild(proxy); | ||
| 79 | + proxy.addChild(createBtn("2")); | ||
| 80 | + var testBtn = createBtn("3") | ||
| 81 | + proxy.addChild(testBtn); | ||
| 82 | + proxy.addChild(createBtn("4")); | ||
| 83 | + | ||
| 84 | + outer.addChild(createBtn("5")); | ||
| 85 | + | ||
| 86 | + function testAction(views: Array<viewModule.View>) { | ||
| 87 | + assertNativeChildren(outer, ["1", "2", "3", "4", "5"]); | ||
| 88 | + proxy.removeChild(testBtn); | ||
| 89 | + assertNativeChildren(outer, ["1", "2", "4", "5"]); | ||
| 90 | + }; | ||
| 91 | + | ||
| 92 | + helper.buildUIAndRunTest(outer, testAction); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + export function test_insert_inside_porxy() { | ||
| 96 | + var outer = new StackLayout(); | ||
| 97 | + var proxy = new ProxyViewContainer(); | ||
| 98 | + | ||
| 99 | + outer.addChild(createBtn("1")); | ||
| 100 | + | ||
| 101 | + outer.addChild(proxy); | ||
| 102 | + proxy.addChild(createBtn("2")); | ||
| 103 | + proxy.addChild(createBtn("4")); | ||
| 104 | + | ||
| 105 | + outer.addChild(createBtn("5")); | ||
| 106 | + | ||
| 107 | + function testAction(views: Array<viewModule.View>) { | ||
| 108 | + assertNativeChildren(outer, ["1", "2", "4", "5"]); | ||
| 109 | + proxy.insertChild(createBtn("3"), 1); | ||
| 110 | + assertNativeChildren(outer, ["1", "2", "3", "4", "5"]); | ||
| 111 | + }; | ||
| 112 | + | ||
| 113 | + helper.buildUIAndRunTest(outer, testAction); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + export function test_insert_after_porxy() { | ||
| 117 | + var outer = new StackLayout(); | ||
| 118 | + var proxy = new ProxyViewContainer(); | ||
| 119 | + | ||
| 120 | + outer.addChild(createBtn("1")); | ||
| 121 | + | ||
| 122 | + outer.addChild(proxy); | ||
| 123 | + proxy.addChild(createBtn("2")); | ||
| 124 | + proxy.addChild(createBtn("3")); | ||
| 125 | + proxy.addChild(createBtn("4")); | ||
| 126 | + | ||
| 127 | + function testAction(views: Array<viewModule.View>) { | ||
| 128 | + assertNativeChildren(outer, ["1", "2", "3", "4"]); | ||
| 129 | + outer.insertChild(createBtn("5"), 2); | ||
| 130 | + assertNativeChildren(outer, ["1", "2", "3", "4", "5"]); | ||
| 131 | + }; | ||
| 132 | + | ||
| 133 | + helper.buildUIAndRunTest(outer, testAction); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + function createBtn(text: string): Button { | ||
| 137 | + var b = new Button(); | ||
| 138 | + b.text = text; | ||
| 139 | + return b; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + function assertNativeChildren(stack: StackLayout, arr: Array<string>) { | ||
| 143 | + if (stack.android) { | ||
| 144 | + let android: org.nativescript.widgets.StackLayout = stack.android; | ||
| 145 | + TKUnit.assertEqual(android.getChildCount(), arr.length, "Native children"); | ||
| 146 | + for (let i = 0; i < arr.length; i++) { | ||
| 147 | + let nativeBtn = <android.widget.Button>android.getChildAt(i); | ||
| 148 | + TKUnit.assertEqual(nativeBtn.getText(), arr[i]); | ||
| 149 | + } | ||
| 150 | + } else if (stack.ios) { | ||
| 151 | + let ios: UIView = stack.ios; | ||
| 152 | + TKUnit.assertEqual(ios.subviews.count, arr.length, "Native children"); | ||
| 153 | + for (let i = 0; i < arr.length; i++) { | ||
| 154 | + let nativeBtn = <UIButton>ios.subviews[i]; | ||
| 155 | + TKUnit.assertEqual(nativeBtn.titleLabel.text, arr[i]); | ||
| 156 | + } | ||
| 157 | + } else { | ||
| 158 | + TKUnit.assert(false, "No native view to assert"); | ||
| 159 | + } | ||
| 160 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -265,6 +265,7 @@ | |||
| 265 | 265 | "apps/tests/ui/page/test-page-module.ts", | |
| 266 | 266 | "apps/tests/ui/placeholder/placeholder-tests.ts", | |
| 267 | 267 | "apps/tests/ui/progress/progress-tests.ts", | |
| 268 | + "apps/tests/ui/proxy-view-container/proxy-view-container-tests.ts", | ||
| 268 | 269 | "apps/tests/ui/repeater/repeater-tests.ts", | |
| 269 | 270 | "apps/tests/ui/repeater/repeaterItems-bindingToGestures.ts", | |
| 270 | 271 | "apps/tests/ui/scroll-view/scroll-view-tests.ts", | |
@@ -594,6 +595,8 @@ | |||
| 594 | 595 | "ui/progress/progress.android.ts", | |
| 595 | 596 | "ui/progress/progress.d.ts", | |
| 596 | 597 | "ui/progress/progress.ios.ts", | |
| 598 | + "ui/proxy-view-container/proxy-view-container.d.ts", | ||
| 599 | + "ui/proxy-view-container/proxy-view-container.ts", | ||
| 597 | 600 | "ui/repeater/repeater.d.ts", | |
| 598 | 601 | "ui/repeater/repeater.ts", | |
| 599 | 602 | "ui/scroll-view/scroll-view-common.ts", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ registerSpecialProperty("class", (instance: definition.View, propertyValue: stri | |||
| 22 | 22 | instance.className = propertyValue; | |
| 23 | 23 | }); | |
| 24 | 24 | ||
| 25 | - function getEventOrGestureName(name: string) : string { | ||
| 25 | + function getEventOrGestureName(name: string): string { | ||
| 26 | 26 | return name.indexOf("on") === 0 ? name.substr(2, name.length - 2) : name; | |
| 27 | 27 | } | |
| 28 | 28 | ||
@@ -190,7 +190,7 @@ export class View extends ProxyObject implements definition.View { | |||
| 190 | 190 | observe(type: gestures.GestureTypes, callback: (args: gestures.GestureEventData) => void, thisArg?: any): void { | |
| 191 | 191 | if (!this._gestureObservers[type]) { | |
| 192 | 192 | this._gestureObservers[type] = []; | |
| 193 | - } | ||
| 193 | + } | ||
| 194 | 194 | ||
| 195 | 195 | this._gestureObservers[type].push(gestures.observe(this, type, callback, thisArg)); | |
| 196 | 196 | } | |
@@ -926,6 +926,26 @@ export class View extends ProxyObject implements definition.View { | |||
| 926 | 926 | // | |
| 927 | 927 | } | |
| 928 | 928 | ||
| 929 | + _childIndexToNativeChildIndex(index?: number): number { | ||
| 930 | + return index; | ||
| 931 | + } | ||
| 932 | + | ||
| 933 | + _getNativeViewsCount(): number { | ||
| 934 | + return this._isAddedToNativeVisualTree ? 1 : 0; | ||
| 935 | + } | ||
| 936 | + | ||
| 937 | + _eachLayoutView(callback: (View) => void): void { | ||
| 938 | + return callback(this); | ||
| 939 | + } | ||
| 940 | + | ||
| 941 | + _addToSuperview(superview: any, index?: number): boolean { | ||
| 942 | + // IOS specific | ||
| 943 | + return false; | ||
| 944 | + } | ||
| 945 | + _removeFromSuperview(): void { | ||
| 946 | + // IOS specific | ||
| 947 | + } | ||
| 948 | + | ||
| 929 | 949 | /** | |
| 930 | 950 | * Core logic for adding a child view to this instance. Used by the framework to handle lifecycle events more centralized. Do not outside the UI Stack implementation. | |
| 931 | 951 | * // TODO: Think whether we need the base Layout routine. | |
@@ -954,7 +974,8 @@ export class View extends ProxyObject implements definition.View { | |||
| 954 | 974 | view.style._inheritStyleProperties(); | |
| 955 | 975 | ||
| 956 | 976 | if (!view._isAddedToNativeVisualTree) { | |
| 957 | - view._isAddedToNativeVisualTree = this._addViewToNativeVisualTree(view, atIndex); | ||
| 977 | + var nativeIndex = this._childIndexToNativeChildIndex(atIndex); | ||
| 978 | + view._isAddedToNativeVisualTree = this._addViewToNativeVisualTree(view, nativeIndex); | ||
| 958 | 979 | } | |
| 959 | 980 | ||
| 960 | 981 | // TODO: Discuss this. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -445,7 +445,7 @@ declare module "ui/core/view" { | |||
| 445 | 445 | * Sets in-line CSS string as style. | |
| 446 | 446 | * @param style - In-line CSS string. | |
| 447 | 447 | */ | |
| 448 | - public setInlineStyle(style: string) : void; | ||
| 448 | + public setInlineStyle(style: string): void; | ||
| 449 | 449 | ||
| 450 | 450 | public getGestureObservers(type: gestures.GestureTypes): Array<gestures.GesturesObserver>; | |
| 451 | 451 | ||
@@ -497,6 +497,14 @@ declare module "ui/core/view" { | |||
| 497 | 497 | _removeView(view: View); | |
| 498 | 498 | _context: any /* android.content.Context */; | |
| 499 | 499 | ||
| 500 | + _childIndexToNativeChildIndex(index?: number): number; | ||
| 501 | + _getNativeViewsCount(): number; | ||
| 502 | + | ||
| 503 | + _eachLayoutView(callback: (View) => void): void; | ||
| 504 | + | ||
| 505 | + _addToSuperview(superview: any, index?: number): boolean; | ||
| 506 | + _removeFromSuperview(); | ||
| 507 | + | ||
| 500 | 508 | public _applyXmlAttribute(attribute: string, value: any): boolean; | |
| 501 | 509 | ||
| 502 | 510 | // TODO: Implement logic for stripping these lines out | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | - import viewCommon = require("./view-common"); | ||
| 1 | + import types = require("utils/types"); | ||
| 2 | + import viewCommon = require("./view-common"); | ||
| 2 | 3 | import trace = require("trace"); | |
| 3 | 4 | import utils = require("utils/utils"); | |
| 4 | 5 | import dependencyObservable = require("ui/core/dependency-observable"); | |
@@ -265,6 +266,26 @@ export class View extends viewCommon.View { | |||
| 265 | 266 | if (this._cachedFrame) { | |
| 266 | 267 | this._setNativeViewFrame(this._nativeView, this._cachedFrame); | |
| 267 | 268 | } | |
| 269 | + } | ||
| 270 | + | ||
| 271 | + public _addToSuperview(superview: any, atIndex?: number): boolean { | ||
| 272 | + if (superview && this._nativeView) { | ||
| 273 | + if (types.isNullOrUndefined(atIndex) || atIndex >= superview.subviews.count) { | ||
| 274 | + superview.addSubview(this._nativeView); | ||
| 275 | + } else { | ||
| 276 | + superview.insertSubviewAtIndex(this._nativeView, atIndex); | ||
| 277 | + } | ||
| 278 | + | ||
| 279 | + return true; | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + return false; | ||
| 283 | + } | ||
| 284 | + | ||
| 285 | + public _removeFromSuperview() { | ||
| 286 | + if (this._nativeView) { | ||
| 287 | + this._nativeView.removeFromSuperview(); | ||
| 288 | + } | ||
| 268 | 289 | } | |
| 269 | 290 | } | |
| 270 | 291 | ||
@@ -290,30 +311,15 @@ export class CustomLayoutView extends View { | |||
| 290 | 311 | } | |
| 291 | 312 | ||
| 292 | 313 | public _addViewToNativeVisualTree(child: View, atIndex: number): boolean { | |
| 293 | - super._addViewToNativeVisualTree(child); | ||
| 314 | + super._addViewToNativeVisualTree(child, atIndex); | ||
| 294 | 315 | ||
| 295 | - if (this._nativeView && child._nativeView) { | ||
| 296 | - var types = require("utils/types"); | ||
| 297 | - | ||
| 298 | - if (types.isNullOrUndefined(atIndex) || atIndex >= this._nativeView.subviews.count) { | ||
| 299 | - this._nativeView.addSubview(child._nativeView); | ||
| 300 | - } | ||
| 301 | - else { | ||
| 302 | - this._nativeView.insertSubviewAtIndex(child._nativeView, atIndex); | ||
| 303 | - } | ||
| 304 | - | ||
| 305 | - return true; | ||
| 306 | - } | ||
| 307 | - | ||
| 308 | - return false; | ||
| 316 | + return child._addToSuperview(this._nativeView, atIndex); | ||
| 309 | 317 | } | |
| 310 | 318 | ||
| 311 | 319 | public _removeViewFromNativeVisualTree(child: View): void { | |
| 312 | 320 | super._removeViewFromNativeVisualTree(child); | |
| 313 | 321 | ||
| 314 | - if (child._nativeView) { | ||
| 315 | - child._nativeView.removeFromSuperview(); | ||
| 316 | - } | ||
| 322 | + child._removeFromSuperview(); | ||
| 317 | 323 | } | |
| 318 | 324 | } | |
| 319 | 325 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments