Skip to content

Commit

Permalink
implements #64
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterStaev committed Jun 23, 2017
1 parent 35dff27 commit 282d9a4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
3 changes: 3 additions & 0 deletions demo/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
color: green;
text-align: right;
}
.default:disabled {
opacity: 0.5
}

StackLayout {
horizontal-align: center;
Expand Down
1 change: 1 addition & 0 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function pageLoaded(args: EventData) {
viewModel.set("items", items);
viewModel.set("hint", "My Hint");
viewModel.set("selectedIndex", null);
viewModel.set("isEnabled", true);
viewModel.set("cssClass", "default");

page.bindingContext = viewModel;
Expand Down
17 changes: 11 additions & 6 deletions demo/app/main-page.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" xmlns:dd="nativescript-drop-down">
<GridLayout rows="auto, auto, auto, auto, auto, *" columns="auto, *">
<GridLayout rows="auto, auto, auto, auto, auto, auto, *" columns="auto, *">
<dd:DropDown id="dd" hint="{{ hint }}" items="{{ items }}" selectedIndex="{{ selectedIndex }}"
opened="dropDownOpened" closed="dropDownClosed" selectedIndexChanged="dropDownSelectedIndexChanged"
class="{{ cssClass }}"
row="0" colSpan="2" />
class="{{ cssClass }}" isEnabled="{{ isEnabled }}"
row="0" colSpan="2" />

<Label text="Selected Index:" row="1" col="0" fontSize="18" verticalAlignment="bottom"/>
<TextField text="{{ selectedIndex }}" row="1" col="1" />
<Button row="2" col="0" colSpan="2" tap="changeStyles" text="Change Styles" style="font-size: 25" />
<Button row="3" col="0" colSpan="2" tap="open" text="Open" style="font-size: 25" />
<Button row="4" col="0" colSpan="2" tap="close" text="Close" style="font-size: 25" />

<Label text="Enabled?" row="2" col="0" fontSize="18" verticalAlignment="bottom"/>
<Switch checked="{{ isEnabled }}" row="2" col="1" horizontalAlignment="left" />

<Button row="3" col="0" colSpan="2" tap="changeStyles" text="Change Styles" style="font-size: 25" />
<Button row="4" col="0" colSpan="2" tap="open" text="Open" style="font-size: 25" />
<Button row="5" col="0" colSpan="2" tap="close" text="Close" style="font-size: 25" />
</GridLayout>
</Page>
4 changes: 3 additions & 1 deletion drop-down.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export class DropDown extends DropDownBase {
}

public open() {
this.nativeView.performClick();
if (this.isEnabled) {
this.nativeView.performClick();
}
}

public close() {
Expand Down
10 changes: 8 additions & 2 deletions drop-down.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ export class DropDown extends DropDownBase {
}

public open() {
this.ios.becomeFirstResponder();
if (this.isEnabled) {
this.ios.becomeFirstResponder();
}
}

public close() {
Expand Down Expand Up @@ -510,7 +512,11 @@ class TNSDropDownLabel extends TNSLabel {
@ObjCMethod()
public tap( @ObjCParam(UITapGestureRecognizer) sender: UITapGestureRecognizer) {
if (sender.state === UIGestureRecognizerState.Ended) {
this.becomeFirstResponder();
const owner = this._owner.get();

if (owner.isEnabled) {
this.becomeFirstResponder();
}
}
}

Expand Down

0 comments on commit 282d9a4

Please sign in to comment.