mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #220 from NativeScript/feature/toolbar
Add optionsMenu
This commit is contained in:
@@ -118,8 +118,12 @@
|
||||
<TypeScriptCompile Include="apps\tests\layouts\layout-helper.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\layouts\wrap-layout-tests.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\pages\page12.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\pages\page16.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\pages\page15.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\pages\page13.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\pages\page17.ts">
|
||||
<DependentUpon>page17.xml</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="apps\tests\pages\property-bindings.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\platform-tests.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\fps-meter-tests.ts" />
|
||||
@@ -330,6 +334,16 @@
|
||||
<TypeScriptCompile Include="ui\list-picker\list-picker.ios.ts">
|
||||
<DependentUpon>list-picker.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="ui\tool-bar\tool-bar-common.ts">
|
||||
<DependentUpon>tool-bar.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="ui\tool-bar\tool-bar.android.ts">
|
||||
<DependentUpon>tool-bar.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="ui\tool-bar\tool-bar.d.ts" />
|
||||
<TypeScriptCompile Include="ui\tool-bar\tool-bar.ios.ts">
|
||||
<DependentUpon>tool-bar.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="ui\segmented-bar\segmented-bar-common.ts">
|
||||
<DependentUpon>segmented-bar.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
@@ -499,10 +513,6 @@
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="ui\text-view\text-view.d.ts" />
|
||||
<TypeScriptCompile Include="utils\android_constants.ts" />
|
||||
<TypeScriptCompile Include="utils\containers.d.ts" />
|
||||
<TypeScriptCompile Include="utils\containers.ts">
|
||||
<DependentUpon>containers.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="utils\module-merge.ts" />
|
||||
<TypeScriptCompile Include="utils\utils.android.ts">
|
||||
<DependentUpon>utils.d.ts</DependentUpon>
|
||||
@@ -568,6 +578,10 @@
|
||||
<Content Include="apps\tests\file-name-resolver-tests\files\test.ios.land.xml" />
|
||||
<Content Include="apps\tests\file-name-resolver-tests\files\test.android.minWH600.xml" />
|
||||
<Content Include="apps\tests\file-name-resolver-tests\files\test.xml" />
|
||||
<Content Include="apps\tests\pages\page17.xml">
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
<Content Include="apps\tests\test-icon.png" />
|
||||
<Content Include="apps\ui-tests-app\pages\i86.xml" />
|
||||
<Content Include="apps\template-blank\app.css" />
|
||||
<Content Include="apps\template-hello-world\app.css" />
|
||||
@@ -1453,6 +1467,9 @@
|
||||
<Content Include="ui\list-picker\package.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="ui\tool-bar\package.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="build\tslint.json" />
|
||||
@@ -1507,7 +1524,7 @@
|
||||
<AutoAssignPort>True</AutoAssignPort>
|
||||
<DevelopmentServerPort>0</DevelopmentServerPort>
|
||||
<DevelopmentServerVPath>/</DevelopmentServerVPath>
|
||||
<IISUrl>http://localhost:7260/</IISUrl>
|
||||
<IISUrl>http://localhost:3128/</IISUrl>
|
||||
<NTLMAuthentication>False</NTLMAuthentication>
|
||||
<UseCustomServer>False</UseCustomServer>
|
||||
<CustomServerUrl>
|
||||
@@ -1518,4 +1535,4 @@
|
||||
<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_2linear-layout_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>
|
||||
</Project>
|
||||
|
||||
55
apps/tests/pages/page16.ts
Normal file
55
apps/tests/pages/page16.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import pageModule = require("ui/page");
|
||||
import buttonModule = require("ui/button");
|
||||
import stackModule = require("ui/layouts/stack-layout");
|
||||
import frame = require("ui/frame");
|
||||
|
||||
export function createPage() {
|
||||
var page = new pageModule.Page();
|
||||
|
||||
var iconItem = new pageModule.MenuItem();
|
||||
iconItem.text = "TEST";
|
||||
|
||||
iconItem.icon = "~/app" + "/tests" + "/test-icon.png"; // use + to stop regex replace during build
|
||||
iconItem.on("tap", () => {
|
||||
console.log("Icon item tapped");
|
||||
});
|
||||
page.optionsMenu.addItem(iconItem);
|
||||
|
||||
var textItem = new pageModule.MenuItem();
|
||||
textItem.text = "SAVE";
|
||||
textItem.on("tap", () => {
|
||||
console.log("Save item tapped");
|
||||
});
|
||||
page.optionsMenu.addItem(textItem);
|
||||
|
||||
var stackLayout = new stackModule.StackLayout();
|
||||
var count = 0;
|
||||
var btn1 = new buttonModule.Button();
|
||||
btn1.text = "add item";
|
||||
btn1.on("tap", () => {
|
||||
console.log("adding menu item");
|
||||
|
||||
var newItem = new pageModule.MenuItem();
|
||||
var text = "item " + count;
|
||||
newItem.text = text
|
||||
newItem.on("tap", () => {
|
||||
console.log("ITEM [" + text + "] tapped");
|
||||
});
|
||||
page.optionsMenu.addItem(newItem);
|
||||
count++;
|
||||
});
|
||||
|
||||
stackLayout.addChild(btn1);
|
||||
|
||||
var btn2 = new buttonModule.Button();
|
||||
btn2.text = "navigate";
|
||||
btn2.on("tap", () => {
|
||||
var nextPage = "app/tests/pages/page16";
|
||||
frame.topmost().navigate(nextPage);
|
||||
});
|
||||
|
||||
stackLayout.addChild(btn2);
|
||||
|
||||
page.content = stackLayout;
|
||||
return page;
|
||||
}
|
||||
20
apps/tests/pages/page17.ts
Normal file
20
apps/tests/pages/page17.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import observable = require("data/observable");
|
||||
import pages = require("ui/page");
|
||||
|
||||
// Event handler for Page "loaded" event attached in main-page.xml
|
||||
export function pageLoaded(args: observable.EventData) {
|
||||
// Get the event sender
|
||||
var page = <pages.Page>args.object;
|
||||
|
||||
var textItem = new pages.MenuItem();
|
||||
textItem.text = "from loaded";
|
||||
textItem.on("tap", () => {
|
||||
console.log("item added in page.loaded tapped!!!");
|
||||
});
|
||||
page.optionsMenu.addItem(textItem);
|
||||
}
|
||||
|
||||
export function optionTap(args) {
|
||||
console.log("item added form XML tapped!!!");
|
||||
}
|
||||
|
||||
9
apps/tests/pages/page17.xml
Normal file
9
apps/tests/pages/page17.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<Page loaded="pageLoaded">
|
||||
<Page.optionsMenu>
|
||||
<MenuItem text="test" tap="optionTap" android.position="popup" />
|
||||
<MenuItem text="with icon" tap="optionTap" icon="~/app/test-icon.png" android.position="actionBar" />
|
||||
</Page.optionsMenu>
|
||||
<StackLayout>
|
||||
<Button text="button" />
|
||||
</StackLayout>
|
||||
</Page>
|
||||
BIN
apps/tests/test-icon.png
Normal file
BIN
apps/tests/test-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.8 KiB |
@@ -34,6 +34,73 @@ export function addLabelToPage(page: PageModule.Page, text?: string) {
|
||||
page.content = label;
|
||||
}
|
||||
|
||||
export function test_menuItem_inherit_bindingContext() {
|
||||
|
||||
var page: PageModule.Page;
|
||||
var label: LabelModule.Label;
|
||||
var context = { text: "item" };
|
||||
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
page = new PageModule.Page();
|
||||
page.bindingContext = context;
|
||||
var menuItem = new PageModule.MenuItem();
|
||||
|
||||
menuItem.bind({
|
||||
sourceProperty: "text",
|
||||
targetProperty: "text"
|
||||
});
|
||||
|
||||
page.optionsMenu.addItem(menuItem);
|
||||
|
||||
label = new LabelModule.Label();
|
||||
label.text = "Text";
|
||||
page.content = label;
|
||||
return page;
|
||||
};
|
||||
|
||||
helper.navigate(pageFactory);
|
||||
|
||||
try {
|
||||
TKUnit.assertEqual(page.optionsMenu.getItemAt(0).text, "item", "menuItem.text should equal to 'item'");
|
||||
}
|
||||
finally {
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
||||
|
||||
export function test_Setting_OptionsMenu_doesnt_thrown() {
|
||||
|
||||
var page: PageModule.Page;
|
||||
var label: LabelModule.Label;
|
||||
var gotException = false;
|
||||
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
page = new PageModule.Page();
|
||||
var menuItem = new PageModule.MenuItem();
|
||||
menuItem.text = "Item";
|
||||
page.optionsMenu.addItem(menuItem);
|
||||
|
||||
label = new LabelModule.Label();
|
||||
label.text = "Text";
|
||||
page.content = label;
|
||||
return page;
|
||||
};
|
||||
|
||||
try {
|
||||
helper.navigate(pageFactory);
|
||||
}
|
||||
catch (e) {
|
||||
gotException = true;
|
||||
}
|
||||
|
||||
try {
|
||||
TKUnit.assert(!gotException, "Expected: false, Actual: " + gotException);
|
||||
}
|
||||
finally {
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
||||
|
||||
export function test_AfterPageLoaded_is_called_NativeInstance_is_created() {
|
||||
|
||||
var page: PageModule.Page;
|
||||
|
||||
@@ -3,11 +3,12 @@ import PageModule = require("ui/page");
|
||||
import TKUnit = require("../../TKUnit");
|
||||
import LabelModule = require("ui/label");
|
||||
import helper = require("../helper");
|
||||
import view = require("ui/core/view");
|
||||
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(PageTestCommon, exports);
|
||||
|
||||
export var test_NavigateToNewPage_InnerControl = function () {
|
||||
export function test_NavigateToNewPage_InnerControl() {
|
||||
var testPage: PageModule.Page;
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
testPage = new PageModule.Page();
|
||||
@@ -24,3 +25,38 @@ export var test_NavigateToNewPage_InnerControl = function () {
|
||||
TKUnit.assert(label.android === undefined, "InnerControl.android should be undefined after navigate back.");
|
||||
TKUnit.assert(label.isLoaded === false, "InnerControl.isLoaded should become false after navigating back");
|
||||
}
|
||||
|
||||
export function test_NavBar_isVisible_when_MenuItems_areSet() {
|
||||
|
||||
var page: PageModule.Page;
|
||||
var label: LabelModule.Label;
|
||||
var navBarIsVisible = false;
|
||||
|
||||
var handler = function (data) {
|
||||
page.off(view.knownEvents.loaded, handler);
|
||||
navBarIsVisible = (<any>page.frame.ios).showNavigationBar;
|
||||
}
|
||||
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
page = new PageModule.Page();
|
||||
page.on(view.knownEvents.loaded, handler);
|
||||
|
||||
var mi = new PageModule.MenuItem();
|
||||
mi.text = "B";
|
||||
page.optionsMenu.addItem(mi);
|
||||
label = new LabelModule.Label();
|
||||
label.text = "Text";
|
||||
page.content = label;
|
||||
return page;
|
||||
};
|
||||
|
||||
helper.navigate(pageFactory);
|
||||
|
||||
try {
|
||||
TKUnit.assert(navBarIsVisible, "Expected: true, Actual: " + navBarIsVisible);
|
||||
}
|
||||
finally {
|
||||
page.off(view.knownEvents.loaded, handler);
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,27 @@
|
||||
<TabViewItem title="Tab 1">
|
||||
<TabViewItem.view>
|
||||
<StackLayout>
|
||||
|
||||
|
||||
<ToolBar>
|
||||
<ToolBar.items>
|
||||
<ToolBarItem>
|
||||
<ToolBarItem.view>
|
||||
<Label text="Label" />
|
||||
</ToolBarItem.view>
|
||||
</ToolBarItem>
|
||||
<ToolBarItem>
|
||||
<ToolBarItem.view>
|
||||
<Button text="Button" />
|
||||
</ToolBarItem.view>
|
||||
</ToolBarItem>
|
||||
<ToolBarItem>
|
||||
<ToolBarItem.view>
|
||||
<Image url="http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/256/Places-favorites-icon.png" />
|
||||
</ToolBarItem.view>
|
||||
</ToolBarItem>
|
||||
</ToolBar.items>
|
||||
</ToolBar>
|
||||
|
||||
<SegmentedBar selectedIndex="1" style="background-color: red; color: white" selectedBackgroundColor="green">
|
||||
<SegmentedBar.items>
|
||||
<SegmentedBarItem title="MAY 3" />
|
||||
@@ -14,7 +34,7 @@
|
||||
<SegmentedBarItem title="MAY 5" />
|
||||
</SegmentedBar.items>
|
||||
</SegmentedBar>
|
||||
|
||||
|
||||
<ListPicker items="{{ someItems }}" selectedIndex="3"/>
|
||||
<DatePicker year="1976" month="10" day="30" />
|
||||
<TimePicker hour="10" minute="34" />
|
||||
|
||||
@@ -32,9 +32,12 @@ var MODULES = {
|
||||
"WebView": "ui/web-view",
|
||||
"SegmentedBar": "ui/segmented-bar",
|
||||
"SegmentedBarItem": "ui/segmented-bar",
|
||||
"ToolBar": "ui/tool-bar",
|
||||
"ToolBarItem": "ui/tool-bar",
|
||||
"TimePicker": "ui/time-picker",
|
||||
"DatePicker": "ui/date-picker",
|
||||
"ListPicker": "ui/list-picker",
|
||||
"MenuItem": "ui/page",
|
||||
};
|
||||
|
||||
var ROW = "row";
|
||||
@@ -63,7 +66,7 @@ export function getComponentModule(elementName: string, namespace: string, attri
|
||||
// Create instance of the component.
|
||||
instance = new instanceType();
|
||||
} catch (ex) {
|
||||
throw new Error("Cannot create module " + moduleId + ". " + ex);
|
||||
throw new Error("Cannot create module " + moduleId + ". " + ex + ". StackTrace: " + ex.stack);
|
||||
}
|
||||
|
||||
if (instance && instanceModule) {
|
||||
@@ -180,4 +183,4 @@ function isBinding(value: string): boolean {
|
||||
}
|
||||
|
||||
return isBinding;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ class TapHandlerImpl extends NSObject {
|
||||
public static ObjCExposedMethods = {
|
||||
"tap": { returns: interop.types.void, params: [interop.types.id] }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// merge the exports of the common file with the exports of this file
|
||||
|
||||
56
ui/enums/enums.d.ts
vendored
56
ui/enums/enums.d.ts
vendored
@@ -9,25 +9,25 @@
|
||||
* iOS: [UIKeyboardTypeNumbersAndPunctuation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
|
||||
*/
|
||||
export var datetime: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [TYPE_CLASS_PHONE](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_PHONE)
|
||||
* iOS: [UIKeyboardTypePhonePad](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
|
||||
*/
|
||||
export var phone: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [TYPE_CLASS_NUMBER](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_NUMBER) | android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL | [TYPE_NUMBER_FLAG_SIGNED](http://developer.android.com/reference/android/text/InputType.html#TYPE_NUMBER_FLAG_SIGNED) | [TYPE_NUMBER_FLAG_DECIMAL](http://developer.android.com/reference/android/text/InputType.html#TYPE_NUMBER_FLAG_DECIMAL)
|
||||
* iOS: [UIKeyboardTypeNumbersAndPunctuation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
|
||||
*/
|
||||
export var number: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [TYPE_CLASS_TEXT](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_TEXT) | [TYPE_TEXT_VARIATION_URI](http://developer.android.com/reference/android/text/InputType.html#TYPE_TEXT_VARIATION_URI)
|
||||
* iOS: [UIKeyboardTypeURL](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
|
||||
*/
|
||||
export var url: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [TYPE_CLASS_TEXT](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_TEXT) | [TYPE_TEXT_VARIATION_EMAIL_ADDRESS](http://developer.android.com/reference/android/text/InputType.html#TYPE_TEXT_VARIATION_EMAIL_ADDRESS)
|
||||
* iOS: [UIKeyboardTypeEmailAddress](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
|
||||
@@ -56,13 +56,13 @@
|
||||
* iOS: [UIReturnKeyGo](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType)
|
||||
*/
|
||||
export var go: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [IME_ACTION_SEARCH](http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_SEARCH)
|
||||
* iOS: [UIReturnKeySearch](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType)
|
||||
*/
|
||||
export var search: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [IME_ACTION_SEND](http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_SEND)
|
||||
* iOS: [UIReturnKeySend](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType)
|
||||
@@ -304,7 +304,7 @@
|
||||
* Capitalize the first letter of each sentence automatically.
|
||||
*/
|
||||
export var sentences: string;
|
||||
|
||||
|
||||
/**
|
||||
* Capitalize all characters automatically.
|
||||
*/
|
||||
@@ -325,4 +325,44 @@
|
||||
*/
|
||||
export var jpeg: string;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies NavigationBar visibility mode.
|
||||
*/
|
||||
module NavigationBarVisibility {
|
||||
/**
|
||||
* NavigationBar will be visible if there if frame backstack canGoBack is true or Page have optionsMenu with menuItems.
|
||||
*/
|
||||
export var auto: string;
|
||||
|
||||
/**
|
||||
* NavigationBar will be hidden.
|
||||
*/
|
||||
export var never: string;
|
||||
|
||||
/**
|
||||
* NavigationBar will be visible.
|
||||
*/
|
||||
export var always: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies android MenuItem position.
|
||||
*/
|
||||
module MenuItemPosition {
|
||||
/**
|
||||
* Always show this item as a button in an Action Bar.
|
||||
*/
|
||||
export var actionBar: string;
|
||||
|
||||
/**
|
||||
* Show this item as a button in an Action Bar if the system decides there is room for it.
|
||||
*/
|
||||
export var actionBarIfRoom: string;
|
||||
|
||||
/**
|
||||
* Never show this item as a button in an Action Bar.
|
||||
*/
|
||||
export var popup: string;
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,19 @@ export module AutocapitalizationType {
|
||||
export var allCharacters: string = "allCharacters";
|
||||
}
|
||||
|
||||
export module NavigationBarVisibility {
|
||||
export var auto: string = "auto";
|
||||
export var never: string = "never";
|
||||
export var always: string = "always";
|
||||
}
|
||||
|
||||
export module MenuItemPosition {
|
||||
export var actionBar: string = "actionBar";
|
||||
export var actionBarIfRoom: string = "actionBarIfRoom";
|
||||
export var popup: string = "popup";
|
||||
}
|
||||
|
||||
export module ImageFormat {
|
||||
export var png: string = "png";
|
||||
export var jpeg: string = "jpeg";
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ export class Frame extends view.CustomLayoutView implements definition.Frame {
|
||||
}
|
||||
|
||||
get backStack(): Array<definition.BackstackEntry> {
|
||||
return this._backStack;
|
||||
return this._backStack.slice();
|
||||
}
|
||||
|
||||
get currentPage(): pages.Page {
|
||||
@@ -370,6 +370,10 @@ export class Frame extends view.CustomLayoutView implements definition.Frame {
|
||||
public _removeViewFromNativeVisualTree(child: view.View): void {
|
||||
child._isAddedToNativeVisualTree = false;
|
||||
}
|
||||
|
||||
public _invalidateOptionsMenu() {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
var _topmost = function (): Frame {
|
||||
|
||||
@@ -6,6 +6,8 @@ import observable = require("data/observable");
|
||||
import utils = require("utils/utils");
|
||||
import view = require("ui/core/view");
|
||||
import application = require("application");
|
||||
import imageSource = require("image-source");
|
||||
import enums = require("ui/enums");
|
||||
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(frameCommon, exports);
|
||||
@@ -37,6 +39,7 @@ class PageFragmentBody extends android.app.Fragment {
|
||||
onCreate(savedInstanceState: android.os.Bundle) {
|
||||
super.onCreate(savedInstanceState);
|
||||
trace.write(this.getTag() + ".onCreate(); savedInstanceState: " + savedInstanceState, trace.categories.NativeLifecycle);
|
||||
super.setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
onCreateView(inflater: android.view.LayoutInflater, container: android.view.ViewGroup, savedInstanceState: android.os.Bundle): android.view.View {
|
||||
@@ -132,6 +135,53 @@ class PageFragmentBody extends android.app.Fragment {
|
||||
super.onDetach();
|
||||
trace.write(this.getTag() + ".onDetach();", trace.categories.NativeLifecycle);
|
||||
}
|
||||
|
||||
onCreateOptionsMenu(menu: android.view.IMenu, inflater: android.view.MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
|
||||
var page: pages.Page = this.entry.resolvedPage;
|
||||
var items = page.optionsMenu.getItems();
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i];
|
||||
var menuItem = menu.add(android.view.Menu.NONE, i, android.view.Menu.NONE, item.text);
|
||||
if (item.icon) {
|
||||
var img = imageSource.fromResource(item.icon);
|
||||
var drawable = new android.graphics.drawable.BitmapDrawable(img.android);
|
||||
menuItem.setIcon(drawable);
|
||||
}
|
||||
|
||||
var showAsAction = PageFragmentBody.getShowAsAction(item);
|
||||
menuItem.setShowAsAction(showAsAction);
|
||||
}
|
||||
}
|
||||
|
||||
private static getShowAsAction(menuItem: pages.MenuItem): number {
|
||||
switch (menuItem.android.position) {
|
||||
case enums.MenuItemPosition.actionBarIfRoom:
|
||||
return android.view.MenuItem.SHOW_AS_ACTION_IF_ROOM;
|
||||
|
||||
case enums.MenuItemPosition.popup:
|
||||
return android.view.MenuItem.SHOW_AS_ACTION_NEVER;
|
||||
|
||||
case enums.MenuItemPosition.actionBar:
|
||||
default:
|
||||
return android.view.MenuItem.SHOW_AS_ACTION_ALWAYS;
|
||||
}
|
||||
}
|
||||
|
||||
onOptionsItemSelected(item: android.view.IMenuItem) {
|
||||
var page: pages.Page = this.entry.resolvedPage;
|
||||
var itemId = item.getItemId();
|
||||
|
||||
var menuItem = page.optionsMenu.getItemAt(itemId);
|
||||
if (menuItem) {
|
||||
menuItem._raiseTap();
|
||||
return true;
|
||||
}
|
||||
|
||||
super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
function onFragmentShown(fragment: PageFragmentBody) {
|
||||
@@ -314,6 +364,12 @@ export class Frame extends frameCommon.Frame {
|
||||
public _clearAndroidReference() {
|
||||
// we should keep the reference to underlying native object, since frame can contain many pages.
|
||||
}
|
||||
|
||||
public _invalidateOptionsMenu() {
|
||||
if (this.android && this.android.activity) {
|
||||
this.android.activity.invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare module com {
|
||||
@@ -422,7 +478,7 @@ class NativeActivity extends com.tns.NativeScriptActivity {
|
||||
trace.write("NativeScriptActivity.onDestroy();", trace.categories.NativeLifecycle);
|
||||
}
|
||||
|
||||
onOptionsItemSelected(menuItem) {
|
||||
onOptionsItemSelected(menuItem: android.view.IMenuItem) {
|
||||
if (!this.androidFrame.hasListeners(frameCommon.knownEvents.android.optionSelected)) {
|
||||
return false;
|
||||
}
|
||||
@@ -598,10 +654,11 @@ function findPageForFragment(fragment: android.app.Fragment, frame: Frame) {
|
||||
trace.write("Current page matches fragment: " + fragmentTag, trace.categories.NativeLifecycle);
|
||||
}
|
||||
else {
|
||||
for (var i = 0; i < frame.backStack.length; i++) {
|
||||
entry = frame.backStack[i];
|
||||
if (frame.backStack[i].resolvedPage[TAG] === fragmentTag) {
|
||||
entry = frame.backStack[i];
|
||||
var backStack = frame.backStack;
|
||||
for (var i = 0; i < backStack.length; i++) {
|
||||
entry = backStack[i];
|
||||
if (backStack[i].resolvedPage[TAG] === fragmentTag) {
|
||||
entry = backStack[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
9
ui/frame/frame.d.ts
vendored
9
ui/frame/frame.d.ts
vendored
@@ -84,6 +84,7 @@ declare module "ui/frame" {
|
||||
|
||||
//@private
|
||||
_processNavigationQueue(page: pages.Page);
|
||||
_invalidateOptionsMenu();
|
||||
//@endprivate
|
||||
}
|
||||
|
||||
@@ -144,7 +145,7 @@ declare module "ui/frame" {
|
||||
/**
|
||||
* Gets the Android-specific menu item that has been selected.
|
||||
*/
|
||||
item: android.view.MenuItem;
|
||||
item: android.view.IMenuItem;
|
||||
|
||||
/**
|
||||
* True to mark the event as handled (that is to prevent the default processing).
|
||||
@@ -206,6 +207,12 @@ declare module "ui/frame" {
|
||||
* Gets the native [UINavigationController](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UINavigationController_Class/index.html) instance associated with this Frame.
|
||||
*/
|
||||
controller: UINavigationController;
|
||||
|
||||
/**
|
||||
* Gets or sets the visibility of navigationBar.
|
||||
* Use NavBarVisibility enumeration - auto, never, always
|
||||
*/
|
||||
navBarVisibility: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import frameCommon = require("ui/frame/frame-common");
|
||||
import definition = require("ui/frame");
|
||||
import trace = require("trace");
|
||||
import imageSource = require("image-source");
|
||||
import pages = require("ui/page");
|
||||
import enums = require("ui/enums");
|
||||
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(frameCommon, exports);
|
||||
@@ -12,6 +15,7 @@ var navDepth = 0;
|
||||
export class Frame extends frameCommon.Frame {
|
||||
private _ios: iOSFrame;
|
||||
private _paramToNavigate: any;
|
||||
public shouldSkipNativePop: boolean = false;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -35,7 +39,7 @@ export class Frame extends frameCommon.Frame {
|
||||
this._paramToNavigate = param;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public _navigateCore(backstackEntry: definition.BackstackEntry) {
|
||||
var viewController = backstackEntry.resolvedPage.ios;
|
||||
if (!viewController) {
|
||||
@@ -47,9 +51,7 @@ export class Frame extends frameCommon.Frame {
|
||||
animated = this._getIsAnimatedNavigation(backstackEntry.entry);
|
||||
}
|
||||
|
||||
if (this.backStack.length > 0) {
|
||||
this._ios.showNavigationBar = true;
|
||||
}
|
||||
this.updateNavigationBar();
|
||||
|
||||
viewController[ENTRY] = backstackEntry;
|
||||
|
||||
@@ -61,17 +63,29 @@ export class Frame extends frameCommon.Frame {
|
||||
public _goBackCore(entry: definition.NavigationEntry) {
|
||||
navDepth--;
|
||||
trace.write("Frame<" + this._domId + ">.popViewControllerAnimated depth = " + navDepth, trace.categories.Navigation);
|
||||
|
||||
this._ios.controller.allowPop = true;
|
||||
this._ios.controller.popViewControllerAnimated(this._getIsAnimatedNavigation(entry));
|
||||
this._ios.controller.allowPop = false;
|
||||
|
||||
if (this.backStack.length === 0) {
|
||||
this._ios.showNavigationBar = false;
|
||||
if (!this.shouldSkipNativePop) {
|
||||
this._ios.controller.popViewControllerAnimated(this._getIsAnimatedNavigation(entry));
|
||||
}
|
||||
}
|
||||
|
||||
public get ios(): any {
|
||||
public updateNavigationBar(page?: pages.Page): void {
|
||||
switch (this._ios.navBarVisibility) {
|
||||
case enums.NavigationBarVisibility.always:
|
||||
this._ios.showNavigationBar = true;
|
||||
break;
|
||||
|
||||
case enums.NavigationBarVisibility.never:
|
||||
this._ios.showNavigationBar = false;
|
||||
break;
|
||||
|
||||
case enums.NavigationBarVisibility.auto:
|
||||
var pageInstance: pages.Page = page || this.currentPage;
|
||||
this._ios.showNavigationBar = this.backStack.length > 0 || (pageInstance && pageInstance.optionsMenu.getItems().length > 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public get ios(): iOSFrame {
|
||||
return this._ios;
|
||||
}
|
||||
|
||||
@@ -122,9 +136,41 @@ export class Frame extends frameCommon.Frame {
|
||||
var navigationBar = this._ios.controller.navigationBar;
|
||||
return (navigationBar && !this._ios.controller.navigationBarHidden) ? navigationBar.frame.size.height : 0;
|
||||
}
|
||||
|
||||
public _invalidateOptionsMenu() {
|
||||
this.populateMenuItems(this.currentPage);
|
||||
}
|
||||
|
||||
populateMenuItems(page: pages.Page) {
|
||||
var items = page.optionsMenu.getItems();
|
||||
|
||||
var navigationItem: UINavigationItem = (<UIViewController>page.ios).navigationItem;
|
||||
var array: NSMutableArray = items.length > 0 ? NSMutableArray.new() : null;
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i];
|
||||
var tapHandler = TapBarItemHandlerImpl.new().initWithOwner(item);
|
||||
// associate handler with menuItem or it will get collected by JSC.
|
||||
(<any>item).handler = tapHandler;
|
||||
|
||||
var barButtonItem: UIBarButtonItem;
|
||||
if (item.icon) {
|
||||
var img = imageSource.fromResource(item.icon);
|
||||
barButtonItem = UIBarButtonItem.alloc().initWithImageStyleTargetAction(img.ios, UIBarButtonItemStyle.UIBarButtonItemStylePlain, tapHandler, "tap");
|
||||
}
|
||||
else {
|
||||
barButtonItem = UIBarButtonItem.alloc().initWithTitleStyleTargetAction(item.text, UIBarButtonItemStyle.UIBarButtonItemStylePlain, tapHandler, "tap");
|
||||
}
|
||||
|
||||
array.addObject(barButtonItem);
|
||||
}
|
||||
|
||||
if (array) {
|
||||
navigationItem.setRightBarButtonItemsAnimated(array, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* tslint:disable */
|
||||
class UINavigationControllerImpl extends UINavigationController implements UINavigationControllerDelegate {
|
||||
public static ObjCProtocols = [UINavigationControllerDelegate];
|
||||
|
||||
@@ -132,21 +178,13 @@ class UINavigationControllerImpl extends UINavigationController implements UINav
|
||||
return <UINavigationControllerImpl>super.new();
|
||||
}
|
||||
|
||||
private _owner: frameCommon.Frame;
|
||||
|
||||
public initWithOwner(owner: frameCommon.Frame): UINavigationControllerImpl {
|
||||
private _owner: Frame;
|
||||
|
||||
public initWithOwner(owner: Frame): UINavigationControllerImpl {
|
||||
this._owner = owner;
|
||||
return this;
|
||||
}
|
||||
|
||||
private _allowPop: boolean;
|
||||
public get allowPop(): boolean {
|
||||
return this._allowPop;
|
||||
}
|
||||
public set allowPop(value: boolean) {
|
||||
this._allowPop = value;
|
||||
}
|
||||
|
||||
public viewDidLoad(): void {
|
||||
this.view.autoresizesSubviews = false;
|
||||
this.view.autoresizingMask = UIViewAutoresizing.UIViewAutoresizingNone;
|
||||
@@ -158,39 +196,37 @@ class UINavigationControllerImpl extends UINavigationController implements UINav
|
||||
this._owner._updateLayout();
|
||||
}
|
||||
|
||||
public popViewControllerAnimated(animated: boolean): UIViewController {
|
||||
if (this.allowPop) {
|
||||
return super.popViewControllerAnimated(animated);
|
||||
}
|
||||
else {
|
||||
var currentControler = this._owner.currentPage.ios;
|
||||
this._owner.goBack();
|
||||
return currentControler;
|
||||
}
|
||||
}
|
||||
public navigationControllerDidShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
|
||||
|
||||
var frame: Frame = this._owner;
|
||||
var backStack = frame.backStack;
|
||||
var currentEntry = backStack.length > 0 ? backStack[backStack.length - 1] : null;
|
||||
var newEntry: definition.BackstackEntry = viewController[ENTRY];
|
||||
|
||||
if (newEntry === currentEntry && currentEntry) {
|
||||
try {
|
||||
frame.shouldSkipNativePop = true;
|
||||
frame.goBack();
|
||||
}
|
||||
finally {
|
||||
frame.shouldSkipNativePop = false;
|
||||
}
|
||||
}
|
||||
|
||||
public navigationControllerWillShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
|
||||
var frame = this._owner;
|
||||
var page = frame.currentPage;
|
||||
if (page) {
|
||||
frame._removeView(page);
|
||||
}
|
||||
|
||||
var newEntry: definition.BackstackEntry = viewController[ENTRY];
|
||||
var newPage = newEntry.resolvedPage;
|
||||
|
||||
frame._currentEntry = newEntry;
|
||||
frame._addView(newPage);
|
||||
|
||||
frame.populateMenuItems(newPage);
|
||||
frame.updateNavigationBar();
|
||||
|
||||
// notify the page
|
||||
newPage.onNavigatedTo(newEntry.entry.context);
|
||||
}
|
||||
|
||||
public navigationControllerDidShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
|
||||
var frame: frameCommon.Frame = this._owner;
|
||||
var newEntry: definition.BackstackEntry = viewController[ENTRY];
|
||||
var newPage = newEntry.resolvedPage;
|
||||
|
||||
frame._processNavigationQueue(newPage);
|
||||
}
|
||||
|
||||
@@ -199,16 +235,19 @@ class UINavigationControllerImpl extends UINavigationController implements UINav
|
||||
}
|
||||
}
|
||||
|
||||
/* tslint:disable */
|
||||
class iOSFrame implements definition.iOSFrame {
|
||||
/* tslint:enable */
|
||||
/* tslint:enable */
|
||||
private _controller: UINavigationControllerImpl;
|
||||
private _showNavigationBar: boolean;
|
||||
private _navBarVisibility: string;
|
||||
|
||||
constructor(owner: frameCommon.Frame) {
|
||||
constructor(owner: Frame) {
|
||||
this._controller = UINavigationControllerImpl.new().initWithOwner(owner);
|
||||
this._controller.delegate = this._controller;
|
||||
this._controller.automaticallyAdjustsScrollViewInsets = false;
|
||||
this.showNavigationBar = false;
|
||||
this._navBarVisibility = enums.NavigationBarVisibility.auto;
|
||||
}
|
||||
|
||||
public get controller() {
|
||||
@@ -222,4 +261,32 @@ class iOSFrame implements definition.iOSFrame {
|
||||
this._showNavigationBar = value;
|
||||
this._controller.navigationBarHidden = !value;
|
||||
}
|
||||
}
|
||||
|
||||
public get navBarVisibility(): string {
|
||||
return this._navBarVisibility;
|
||||
}
|
||||
public set navBarVisibility(value: string) {
|
||||
this._navBarVisibility = value;
|
||||
}
|
||||
}
|
||||
|
||||
class TapBarItemHandlerImpl extends NSObject {
|
||||
static new(): TapBarItemHandlerImpl {
|
||||
return <TapBarItemHandlerImpl>super.new();
|
||||
}
|
||||
|
||||
private _owner: pages.MenuItem;
|
||||
|
||||
public initWithOwner(owner: pages.MenuItem): TapBarItemHandlerImpl {
|
||||
this._owner = owner;
|
||||
return this;
|
||||
}
|
||||
|
||||
public tap(args) {
|
||||
this._owner._raiseTap();
|
||||
}
|
||||
|
||||
public static ObjCExposedMethods = {
|
||||
"tap": { returns: interop.types.void, params: [interop.types.id] }
|
||||
};
|
||||
}
|
||||
11
ui/layouts/absolute-layout/absolute-layout.d.ts
vendored
11
ui/layouts/absolute-layout/absolute-layout.d.ts
vendored
@@ -1,12 +1,23 @@
|
||||
declare module "ui/layouts/absolute-layout" {
|
||||
import layout = require("ui/layouts/layout");
|
||||
import view = require("ui/core/view");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
|
||||
/**
|
||||
* A layout that lets you specify exact locations (left/top coordinates) of its children.
|
||||
*/
|
||||
class AbsoluteLayout extends layout.Layout {
|
||||
|
||||
/**
|
||||
* Represents the observable property backing the left property.
|
||||
*/
|
||||
public static leftProperty: dependencyObservable.Property;
|
||||
|
||||
/**
|
||||
* Represents the observable property backing the top property.
|
||||
*/
|
||||
public static topProperty: dependencyObservable.Property;
|
||||
|
||||
/**
|
||||
* Gets the value of the Left property from a given View.
|
||||
*/
|
||||
|
||||
@@ -17,10 +17,10 @@ function onPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
|
||||
export class AbsoluteLayout extends layouts.Layout implements definition.AbsoluteLayout {
|
||||
|
||||
public static LeftProperty = new dependencyObservable.Property("Left", "AbsoluteLayout",
|
||||
public static leftProperty = new dependencyObservable.Property("left", "AbsoluteLayout",
|
||||
new dependencyObservable.PropertyMetadata(0, undefined, onPropertyChanged, numberUtils.isFiniteNumber));
|
||||
|
||||
public static TopProperty = new dependencyObservable.Property("Top", "AbsoluteLayout",
|
||||
public static topProperty = new dependencyObservable.Property("top", "AbsoluteLayout",
|
||||
new dependencyObservable.PropertyMetadata(0, undefined, onPropertyChanged, numberUtils.isFiniteNumber));
|
||||
|
||||
public static getLeft(element: view.View): number {
|
||||
@@ -28,14 +28,14 @@ export class AbsoluteLayout extends layouts.Layout implements definition.Absolut
|
||||
throw new Error("element cannot be null or undefinied.");
|
||||
}
|
||||
|
||||
return element._getValue(AbsoluteLayout.LeftProperty);
|
||||
return element._getValue(AbsoluteLayout.leftProperty);
|
||||
}
|
||||
|
||||
public static setLeft(element: view.View, value: number): void {
|
||||
if (!element) {
|
||||
throw new Error("element cannot be null or undefinied.");
|
||||
}
|
||||
element._setValue(AbsoluteLayout.LeftProperty, value);
|
||||
element._setValue(AbsoluteLayout.leftProperty, value);
|
||||
}
|
||||
|
||||
public static getTop(element: view.View): number {
|
||||
@@ -43,14 +43,14 @@ export class AbsoluteLayout extends layouts.Layout implements definition.Absolut
|
||||
throw new Error("element cannot be null or undefinied.");
|
||||
}
|
||||
|
||||
return element._getValue(AbsoluteLayout.TopProperty);
|
||||
return element._getValue(AbsoluteLayout.topProperty);
|
||||
}
|
||||
|
||||
public static setTop(element: view.View, value: number): void {
|
||||
if (!element) {
|
||||
throw new Error("element cannot be null or undefinied.");
|
||||
}
|
||||
element._setValue(AbsoluteLayout.TopProperty, value);
|
||||
element._setValue(AbsoluteLayout.topProperty, value);
|
||||
}
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
|
||||
@@ -5,19 +5,31 @@ import frame = require("ui/frame");
|
||||
import styleScope = require("ui/styling/style-scope");
|
||||
import fs = require("file-system");
|
||||
import fileSystemAccess = require("file-system/file-system-access");
|
||||
import bindable = require("ui/core/bindable");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import enums = require("ui/enums");
|
||||
|
||||
var OPTIONS_MENU = "optionsMenu";
|
||||
|
||||
export module knownEvents {
|
||||
export var navigatedTo = "navigatedTo";
|
||||
export var tap = "tap";
|
||||
}
|
||||
|
||||
export class Page extends contentView.ContentView implements dts.Page {
|
||||
export module knownCollections {
|
||||
export var optionsMenu = "optionsMenu";
|
||||
}
|
||||
|
||||
export class Page extends contentView.ContentView implements dts.Page, view.AddArrayFromBuilder {
|
||||
private _navigationContext: any;
|
||||
|
||||
private _cssApplied: boolean;
|
||||
private _styleScope: styleScope.StyleScope = new styleScope.StyleScope();
|
||||
private _optionsMenu: OptionsMenu;
|
||||
|
||||
constructor(options?: dts.Options) {
|
||||
super(options);
|
||||
this._optionsMenu = new OptionsMenu(this);
|
||||
}
|
||||
|
||||
public onLoaded() {
|
||||
@@ -40,6 +52,13 @@ export class Page extends contentView.ContentView implements dts.Page {
|
||||
this._refreshCss();
|
||||
}
|
||||
|
||||
get optionsMenu(): OptionsMenu {
|
||||
return this._optionsMenu;
|
||||
}
|
||||
set optionsMenu(value: OptionsMenu) {
|
||||
throw new Error("optionsMenu property is read-only");
|
||||
}
|
||||
|
||||
private _refreshCss(): void {
|
||||
if (this._cssApplied) {
|
||||
this._resetCssValues();
|
||||
@@ -131,4 +150,120 @@ export class Page extends contentView.ContentView implements dts.Page {
|
||||
view.eachDescendant(this, resetCssValuesFunc);
|
||||
|
||||
}
|
||||
|
||||
public _addArrayFromBuilder(name: string, value: Array<any>) {
|
||||
if (name === OPTIONS_MENU) {
|
||||
this.optionsMenu.setItems(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class OptionsMenu implements dts.OptionsMenu {
|
||||
private _items: Array<MenuItem> = new Array<MenuItem>();
|
||||
private _page: Page;
|
||||
|
||||
constructor(page: Page) {
|
||||
this._page = page;
|
||||
}
|
||||
|
||||
public addItem(item: MenuItem): void {
|
||||
if (!item) {
|
||||
throw new Error("Cannot add empty item");
|
||||
}
|
||||
|
||||
this._items.push(item);
|
||||
item.menu = this;
|
||||
item.bind({
|
||||
sourceProperty: "bindingContext",
|
||||
targetProperty: "bindingContext"
|
||||
}, this._page);
|
||||
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
public removeItem(item: MenuItem): void {
|
||||
if (!item) {
|
||||
throw new Error("Cannot remove empty item");
|
||||
}
|
||||
|
||||
var itemIndex = this._items.indexOf(item);
|
||||
if (itemIndex < 0) {
|
||||
throw new Error("Cannot find item to remove");
|
||||
}
|
||||
|
||||
item.menu = undefined;
|
||||
item.unbind("bindingContext");
|
||||
this._items.splice(itemIndex, 1);
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
public getItems(): Array<MenuItem> {
|
||||
return this._items.slice();
|
||||
}
|
||||
|
||||
public getItemAt(index: number): MenuItem {
|
||||
return this._items[index];
|
||||
}
|
||||
|
||||
public setItems(items: Array<MenuItem>) {
|
||||
this._items = items;
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
invalidate() {
|
||||
if (this._page.frame) {
|
||||
this._page.frame._invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class MenuItem extends bindable.Bindable implements dts.MenuItem {
|
||||
|
||||
public static textProperty = new dependencyObservable.Property(
|
||||
"text", "MenuItem", new dependencyObservable.PropertyMetadata("", null, MenuItem.onItemChanged));
|
||||
|
||||
public static iconProperty = new dependencyObservable.Property(
|
||||
"icon", "MenuItem", new dependencyObservable.PropertyMetadata(null, null, MenuItem.onItemChanged));
|
||||
|
||||
private static onItemChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var menuItem = <MenuItem>data.object;
|
||||
if (menuItem.menu) {
|
||||
menuItem.menu.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private _android: dts.AndroidMenuItemOptions;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
if (global.android) {
|
||||
this._android = {
|
||||
position: enums.MenuItemPosition.actionBar
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
get android(): dts.AndroidMenuItemOptions {
|
||||
return this._android;
|
||||
}
|
||||
|
||||
get text(): string {
|
||||
return this._getValue(MenuItem.textProperty);
|
||||
}
|
||||
set text(value: string) {
|
||||
this._setValue(MenuItem.textProperty, value);
|
||||
}
|
||||
|
||||
get icon(): string {
|
||||
return this._getValue(MenuItem.iconProperty);
|
||||
}
|
||||
set icon(value: string) {
|
||||
this._setValue(MenuItem.iconProperty, value);
|
||||
}
|
||||
|
||||
public _raiseTap() {
|
||||
this._emit(knownEvents.tap);
|
||||
}
|
||||
|
||||
menu: OptionsMenu;
|
||||
}
|
||||
@@ -2,7 +2,8 @@
|
||||
import definition = require("ui/page");
|
||||
import trace = require("trace");
|
||||
|
||||
module.exports.knownEvents = pageCommon.knownEvents;
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(pageCommon, exports);
|
||||
|
||||
export class Page extends pageCommon.Page {
|
||||
private _isBackNavigation = false;
|
||||
|
||||
68
ui/page/page.d.ts
vendored
68
ui/page/page.d.ts
vendored
@@ -6,6 +6,9 @@ declare module "ui/page" {
|
||||
import view = require("ui/core/view");
|
||||
import contentView = require("ui/content-view");
|
||||
import frame = require("ui/frame");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import bindable = require("ui/core/bindable");
|
||||
|
||||
//@private
|
||||
import styleScope = require("ui/styling/style-scope");
|
||||
//@endprivate
|
||||
@@ -30,10 +33,14 @@ declare module "ui/page" {
|
||||
export var navigatedTo: string;
|
||||
}
|
||||
|
||||
export module knownCollections {
|
||||
export var optionsMenu: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a logical unit for navigation (inside Frame).
|
||||
*/
|
||||
export class Page extends contentView.ContentView {
|
||||
export class Page extends contentView.ContentView implements view.AddArrayFromBuilder {
|
||||
|
||||
constructor(options?: Options)
|
||||
|
||||
@@ -64,6 +71,11 @@ declare module "ui/page" {
|
||||
*/
|
||||
frame: frame.Frame;
|
||||
|
||||
/**
|
||||
* Gets the OptionsMenu for this page.
|
||||
*/
|
||||
optionsMenu: OptionsMenu;
|
||||
|
||||
/**
|
||||
* A method called before navigating to the page.
|
||||
* @param context - The data passed to the page through the NavigationEntry.context property.
|
||||
@@ -87,16 +99,20 @@ declare module "ui/page" {
|
||||
*/
|
||||
onNavigatedFrom(isBackNavigation: boolean): void;
|
||||
|
||||
//@private
|
||||
_getStyleScope(): styleScope.StyleScope
|
||||
//@endprivate
|
||||
|
||||
/**
|
||||
* Raised when navigation to the page is finished.
|
||||
*/
|
||||
on(event: string, callback: (data: observable.EventData) => void);
|
||||
|
||||
/**
|
||||
* Raised when navigation to the page is finished.
|
||||
*/
|
||||
on(event: "navigatedTo", callback: (args: NavigatedData) => void);
|
||||
|
||||
//@private
|
||||
_getStyleScope(): styleScope.StyleScope;
|
||||
_addArrayFromBuilder(name: string, value: Array<any>): void;
|
||||
//@endprivate
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,4 +134,44 @@ declare module "ui/page" {
|
||||
*/
|
||||
exports?: any;
|
||||
}
|
||||
}
|
||||
|
||||
export class OptionsMenu {
|
||||
addItem(item: MenuItem): void;
|
||||
removeItem(item: MenuItem): void;
|
||||
getItems(): Array<MenuItem>;
|
||||
getItemAt(index: number): MenuItem;
|
||||
}
|
||||
|
||||
export class MenuItem extends bindable.Bindable {
|
||||
|
||||
/**
|
||||
* Represents the observable property backing the text property.
|
||||
*/
|
||||
public static textProperty: dependencyObservable.Property;
|
||||
|
||||
/**
|
||||
* Represents the observable property backing the icon property.
|
||||
*/
|
||||
public static iconProperty: dependencyObservable.Property;
|
||||
|
||||
text: string;
|
||||
icon: string;
|
||||
android: AndroidMenuItemOptions;
|
||||
on(event: string, callback: (data: observable.EventData) => void);
|
||||
on(event: "tap", callback: (args: observable.EventData) => void);
|
||||
|
||||
//@private
|
||||
_raiseTap(): void;
|
||||
//@endprivate
|
||||
}
|
||||
|
||||
interface AndroidMenuItemOptions {
|
||||
|
||||
/**
|
||||
* Specify if android menuItem should appear in the actionBar or in the popup.
|
||||
* Use values from enums MenuItemPosition.
|
||||
* Changes after menuItem is created are not supported.
|
||||
*/
|
||||
position: string;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,8 @@ import definition = require("ui/page");
|
||||
import viewModule = require("ui/core/view");
|
||||
import trace = require("trace");
|
||||
|
||||
module.exports.knownEvents = pageCommon.knownEvents;
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(pageCommon, exports);
|
||||
|
||||
class UIViewControllerImpl extends UIViewController {
|
||||
static new(): UIViewControllerImpl {
|
||||
@@ -29,7 +30,6 @@ class UIViewControllerImpl extends UIViewController {
|
||||
}
|
||||
}
|
||||
|
||||
/* tslint:enable */
|
||||
export class Page extends pageCommon.Page {
|
||||
private _ios: UIViewController;
|
||||
|
||||
@@ -65,7 +65,7 @@ export class Page extends pageCommon.Page {
|
||||
(<UIViewController>view.ios).removeFromParentViewController();
|
||||
(<UIViewController>view.ios).view.removeFromSuperview();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get ios(): UIViewController {
|
||||
|
||||
2
ui/tool-bar/package.json
Normal file
2
ui/tool-bar/package.json
Normal file
@@ -0,0 +1,2 @@
|
||||
{ "name" : "tool-bar",
|
||||
"main" : "tool-bar.js" }
|
||||
25
ui/tool-bar/tool-bar-common.ts
Normal file
25
ui/tool-bar/tool-bar-common.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import definition = require("ui/tool-bar");
|
||||
import view = require("ui/core/view");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
|
||||
export module knownCollections {
|
||||
export var items = "items";
|
||||
}
|
||||
|
||||
export class ToolBar extends view.View implements definition.ToolBar {
|
||||
public _addArrayFromBuilder(name: string, value: Array<any>) {
|
||||
if (name === "items") {
|
||||
this._setValue(ToolBar.itemsProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
get items(): Array<definition.ToolBarItem> {
|
||||
return this._getValue(ToolBar.itemsProperty);
|
||||
}
|
||||
set items(value: Array<definition.ToolBarItem>) {
|
||||
this._setValue(ToolBar.itemsProperty, value);
|
||||
}
|
||||
|
||||
public static itemsProperty = new dependencyObservable.Property("items", "ToolBar", new proxy.PropertyMetadata(undefined))
|
||||
}
|
||||
27
ui/tool-bar/tool-bar.android.ts
Normal file
27
ui/tool-bar/tool-bar.android.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import common = require("ui/tool-bar/tool-bar-common");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
|
||||
// merge the exports of the common file with the exports of this file
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(common, exports);
|
||||
|
||||
function onItemsPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var view = <ToolBar>data.object;
|
||||
if (!view.android) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
(<proxy.PropertyMetadata>common.ToolBar.itemsProperty.metadata).onSetNativeValue = onItemsPropertyChanged;
|
||||
|
||||
export class ToolBar extends common.ToolBar {
|
||||
private _android: any;
|
||||
|
||||
public _createUI() {
|
||||
this._android = new (<any>android.widget).Toolbar(this._context);
|
||||
}
|
||||
|
||||
get android(): any {
|
||||
return this._android;
|
||||
}
|
||||
}
|
||||
32
ui/tool-bar/tool-bar.d.ts
vendored
Normal file
32
ui/tool-bar/tool-bar.d.ts
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Contains the ToolBar class, which represents a ToolBar component.
|
||||
*/
|
||||
declare module "ui/tool-bar" {
|
||||
import view = require("ui/core/view");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
|
||||
/**
|
||||
* Represents a ToolBar item.
|
||||
*/
|
||||
interface ToolBarItem {
|
||||
/**
|
||||
* Gets or sets the title of the ToolBar.
|
||||
*/
|
||||
view: view.View;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a UI ToolBar component.
|
||||
*/
|
||||
export class ToolBar extends view.View {
|
||||
/**
|
||||
* Gets or sets the items of the ToolBar.
|
||||
*/
|
||||
items: Array<ToolBarItem>;
|
||||
|
||||
/**
|
||||
* Gets or sets the items dependency property of the ToolBar.
|
||||
*/
|
||||
public static itemsProperty: dependencyObservable.Property;
|
||||
}
|
||||
}
|
||||
41
ui/tool-bar/tool-bar.ios.ts
Normal file
41
ui/tool-bar/tool-bar.ios.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import definition = require("ui/tool-bar");
|
||||
import common = require("ui/tool-bar/tool-bar-common");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import view = require("ui/core/view");
|
||||
|
||||
// merge the exports of the common file with the exports of this file
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(common, exports);
|
||||
|
||||
function onItemsPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var bar = <ToolBar>data.object;
|
||||
if (!bar.ios) {
|
||||
return;
|
||||
}
|
||||
|
||||
var items = new NSMutableArray();
|
||||
for (var element in <Array<definition.ToolBarItem>>data.newValue) {
|
||||
if (element.view instanceof view.View) {
|
||||
bar._addView(element.view);
|
||||
items.addObject(element.view.ios);
|
||||
}
|
||||
}
|
||||
|
||||
bar.ios.setItemsAnimated(items, false);
|
||||
}
|
||||
(<proxy.PropertyMetadata>common.ToolBar.itemsProperty.metadata).onSetNativeValue = onItemsPropertyChanged;
|
||||
|
||||
export class ToolBar extends common.ToolBar {
|
||||
private _ios: UIToolbar;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._ios = UIToolbar.new();
|
||||
}
|
||||
|
||||
get ios(): UIToolbar {
|
||||
return this._ios;
|
||||
}
|
||||
}
|
||||
101
utils/containers.d.ts
vendored
101
utils/containers.d.ts
vendored
@@ -1,101 +0,0 @@
|
||||
declare module "utils/containers" {
|
||||
/**
|
||||
* An interface used to compare two instances of a same class.
|
||||
*/
|
||||
interface IEqualityComparer<T> {
|
||||
/**
|
||||
* Compares two instances of a same class.
|
||||
* @param x - First object to compare.
|
||||
* @param y - Second object to compare.
|
||||
* Returns true if objects are equal, otherwise false.
|
||||
*/
|
||||
equals(x: T, y: T): boolean;
|
||||
|
||||
/**
|
||||
* Generates an unique hash code for an object instance.
|
||||
*/
|
||||
getHashCode(obj: T): number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class used to sort arrays.
|
||||
*/
|
||||
class ArraySortHelper {
|
||||
/**
|
||||
* Sorts an array using a comparer function to order elements.
|
||||
* @param keys - The array which will be sorted.
|
||||
* @param index - Starting index for sorting
|
||||
* @param length - How many items to sort.
|
||||
* @param compareFn - A function that compares two array members.
|
||||
*/
|
||||
public static sort<T>(keys: Array<T>, index: number, length: number, compareFn: (a: T, b: T) => number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a collection of keys and values.
|
||||
*/
|
||||
class Dictionary<TKey, TValue> {
|
||||
/**
|
||||
* The size of the dictionary.
|
||||
*/
|
||||
count: number;
|
||||
/**
|
||||
* Creates an instance of a Dictionary.
|
||||
*/
|
||||
constructor(comparer: IEqualityComparer<TKey>);
|
||||
|
||||
/**
|
||||
* Iterates through all items and executes a callback function.
|
||||
* @param callbackfn - A function that will be executed for each item.
|
||||
*/
|
||||
public forEach(callbackfn: (key: TKey, value: TValue) => void);
|
||||
|
||||
/**
|
||||
* Clears the entire Dictionary.
|
||||
*/
|
||||
public clear(): void;
|
||||
|
||||
/**
|
||||
* Removes the item associated with a given key.
|
||||
* @param key - A key to remove.
|
||||
*/
|
||||
public remove(key: TKey): boolean;
|
||||
|
||||
/**
|
||||
* Returns the item associated with a given key.
|
||||
* @param key - A lookup key.
|
||||
*/
|
||||
public get(key: TKey): TValue;
|
||||
|
||||
/**
|
||||
* Returns if an item associated with a given key exist in the Dictionary.
|
||||
* @param key - A lookup key.
|
||||
*/
|
||||
public has(key: TKey): boolean;
|
||||
|
||||
/**
|
||||
* Associates a value with a key.
|
||||
* @param key - A key for the value.
|
||||
* @param value - The real value.
|
||||
*/
|
||||
public set(key: TKey, value: TValue): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* An implementation of IEqualityComparer that works with strings.
|
||||
*/
|
||||
class StringComparer implements IEqualityComparer<string> {
|
||||
/**
|
||||
* Compares two strings.
|
||||
* @param x - First string to compare.
|
||||
* @param y - Second string to compare.
|
||||
* Returns true if strings are equal, otherwise false.
|
||||
*/
|
||||
equals(x: string, y: string): boolean;
|
||||
|
||||
/**
|
||||
* Generates an unique hash code for a string.
|
||||
*/
|
||||
getHashCode(str: string): number;
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
import definition = require("utils/containers");
|
||||
|
||||
export class ArraySortHelper implements definition.ArraySortHelper {
|
||||
|
||||
public static sort<T>(keys: Array<T>, index: number, length: number, compareFn: (a: T, b: T) => number) {
|
||||
|
||||
if (length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (keys.length === length) {
|
||||
keys.sort(compareFn);
|
||||
return;
|
||||
}
|
||||
|
||||
var sorted = keys.splice(index, length);
|
||||
sorted.sort(compareFn);
|
||||
|
||||
var args: Array<Object> = [0, index];
|
||||
keys.splice.apply(keys, args.concat(sorted));
|
||||
}
|
||||
}
|
||||
|
||||
export class StringComparer implements definition.IEqualityComparer<string> {
|
||||
public equals(x: string, y: string): boolean {
|
||||
return x === y;
|
||||
}
|
||||
|
||||
public getHashCode(str: string): number {
|
||||
var res = 0, len = str.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
res = res * 31 + str.charCodeAt(i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
interface Entry<TKey, TValue> {
|
||||
hashCode: number;
|
||||
next: Entry<TKey, TValue>;
|
||||
key: TKey;
|
||||
value: TValue;
|
||||
}
|
||||
|
||||
export class Dictionary<TKey, TValue> implements definition.Dictionary<TKey, TValue> {
|
||||
|
||||
private _comparer: definition.IEqualityComparer<TKey>;
|
||||
private _count: number = 0;
|
||||
private _entries: Array<Entry<TKey, TValue>>;
|
||||
private _version: number = 0;
|
||||
|
||||
constructor(comparer: definition.IEqualityComparer<TKey>) {
|
||||
this._comparer = comparer;
|
||||
this._entries = new Array<Entry<TKey, TValue>>();
|
||||
}
|
||||
|
||||
get count(): number {
|
||||
return this._count;
|
||||
}
|
||||
|
||||
public forEach(callbackfn: (key: TKey, value: TValue) => void) {
|
||||
var currentVersion = this._version;
|
||||
for (var index in this._entries) {
|
||||
var entry = this._entries[index];
|
||||
callbackfn(entry.key, entry.value);
|
||||
if (currentVersion !== this._version) {
|
||||
throw new Error("Cannot modify Dictionary while enumerating.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
if (this.count > 0) {
|
||||
this._entries = new Array<Entry<TKey, TValue>>();
|
||||
this._count = 0;
|
||||
this._version++;
|
||||
}
|
||||
}
|
||||
|
||||
public remove(key: TKey): boolean {
|
||||
if (!key) {
|
||||
throw new Error("key cannot be null/undefined.");
|
||||
}
|
||||
|
||||
var hash = this._comparer.getHashCode(key);
|
||||
var previousEntry: Entry<TKey, TValue> = null;
|
||||
for (var entry = this._entries[hash]; entry; entry = entry.next) {
|
||||
if (entry.hashCode === hash && this._comparer.equals(entry.key, key)) {
|
||||
if (previousEntry) {
|
||||
previousEntry.next = entry.next;
|
||||
}
|
||||
else {
|
||||
this._entries[hash] = entry.next;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
this._count--;
|
||||
this._version++;
|
||||
|
||||
previousEntry = entry;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public get(key: TKey): TValue {
|
||||
var entry = this.findEntry(key);
|
||||
if (entry) {
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public has(key: TKey): boolean {
|
||||
return (this.findEntry(key) ? true : false);
|
||||
}
|
||||
|
||||
public set(key: TKey, value: TValue): void {
|
||||
if (!key) {
|
||||
throw new Error("key cannot be null or undefined.");
|
||||
}
|
||||
|
||||
var hash = this._comparer.getHashCode(key);
|
||||
var lastEntryForHash: Entry<TKey, TValue> = null;
|
||||
for (var entry = this._entries[hash]; entry; entry = entry.next) {
|
||||
lastEntryForHash = entry;
|
||||
if (entry.hashCode === hash && this._comparer.equals(entry.key, key)) {
|
||||
entry.value = value;
|
||||
this._version++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this._count++;
|
||||
|
||||
var newEntry = <Entry<TKey, TValue>>{};
|
||||
newEntry.hashCode = hash;
|
||||
newEntry.key = key;
|
||||
newEntry.value = value;
|
||||
if (lastEntryForHash) {
|
||||
lastEntryForHash.next = newEntry;
|
||||
}
|
||||
else {
|
||||
this._entries[hash] = newEntry;
|
||||
}
|
||||
|
||||
this._version++;
|
||||
}
|
||||
|
||||
private findEntry(key: TKey): Entry<TKey, TValue> {
|
||||
if (!key) {
|
||||
throw new Error("key cannot be null or undefined.");
|
||||
}
|
||||
|
||||
var hash = this._comparer.getHashCode(key);
|
||||
for (var entry = this._entries[hash]; entry; entry = entry.next) {
|
||||
if (entry.hashCode === hash && this._comparer.equals(entry.key, key)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user