Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit 8c3ba8f

Browse files
authored
Merge pull request #255 from NativeScript/tgpetrov/examples-dataform
Added an example for DataForm
2 parents 2885e6b + 625aee7 commit 8c3ba8f

File tree

111 files changed

+1222
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+1222
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<inset xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:insetTop="4dp"
4+
android:insetBottom="4dp">
5+
<selector>
6+
<item android:state_checked="false" android:state_pressed="false">
7+
<layer-list>
8+
<item android:top="-6dp"
9+
android:left="-6dp"
10+
android:right="-6dp"
11+
android:bottom="1dp">
12+
<shape>
13+
<stroke
14+
android:color="@color/reservations_example_header" android:width="1dp"/>
15+
<solid
16+
android:color="#00000000"/>
17+
</shape>
18+
</item>
19+
<item>
20+
<bitmap android:gravity="right" android:src="@drawable/abc_spinner_mtrl_am_alpha"
21+
android:tint="@color/reservations_example_header" />
22+
</item>
23+
</layer-list>
24+
</item>
25+
<item>
26+
<layer-list>
27+
<item android:top="-8dp"
28+
android:left="-8dp"
29+
android:right="-8dp"
30+
android:bottom="0dp">
31+
<shape>
32+
<stroke
33+
android:color="@color/reservations_example_header" android:width="1.5dp"/>
34+
<solid
35+
android:color="#00000000"/>
36+
</shape>
37+
</item>
38+
<item>
39+
<bitmap android:gravity="right" android:src="@drawable/abc_spinner_mtrl_am_alpha"
40+
android:tint="@color/reservations_example_header" />
41+
</item>
42+
</layer-list>
43+
</item>
44+
</selector>
45+
</inset>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<inset xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:insetTop="4dp"
4+
android:insetBottom="4dp">
5+
<selector>
6+
<item android:state_checked="false" android:state_pressed="false">
7+
<layer-list>
8+
<item android:top="-6dp"
9+
android:left="-6dp"
10+
android:right="-6dp"
11+
android:bottom="1dp">
12+
<shape>
13+
<stroke
14+
android:color="@color/reservations_example_header" android:width="1dp"/>
15+
<solid
16+
android:color="#00000000"/>
17+
</shape>
18+
</item>
19+
<item>
20+
<bitmap android:gravity="right" android:src="@drawable/abc_spinner_mtrl_am_alpha"
21+
android:tint="@color/reservations_example_header" />
22+
</item>
23+
</layer-list>
24+
</item>
25+
<item>
26+
<layer-list>
27+
<item android:top="-8dp"
28+
android:left="-8dp"
29+
android:right="-8dp"
30+
android:bottom="0dp">
31+
<shape>
32+
<stroke
33+
android:color="?android:attr/colorControlActivated" android:width="1.5dp"/>
34+
<solid
35+
android:color="#00000000"/>
36+
</shape>
37+
</item>
38+
<item>
39+
<bitmap android:gravity="right" android:src="@drawable/abc_spinner_mtrl_am_alpha"
40+
android:tint="?android:attr/colorControlActivated" />
41+
</item>
42+
</layer-list>
43+
</item>
44+
</selector>
45+
</inset>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<Spinner android:id="@+id/data_form_spinner_editor"
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
style="@style/Widget.AppCompat.Spinner.Underlined"
6+
android:textSize="@dimen/data_form_editor_text_size"
7+
android:background="@drawable/reservation_spinner_background"
8+
android:paddingTop="4dp"
9+
android:paddingBottom="12dp"
10+
android:tint="#FFFFFF"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"/>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@android:id/text1"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:padding="0dp"
7+
android:textColor="#FFFFFF"
8+
android:singleLine="true"
9+
android:ellipsize="marquee"
10+
style="?android:attr/spinnerItemStyle"/>

app/App_Resources/Android/values/colors.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
<color name="ns_mainbg">#E5E5E8</color>
66
<color name="ns_accent">#33B5E5</color>
77
<color name="ns_blue">#3D5AFE</color>
8+
9+
<color name="reservations_example_header">#B1AFAE</color>
810
</resources>
14.3 KB
14.4 KB
14.5 KB
292 Bytes
391 Bytes
520 Bytes
130 KB

app/App_Resources/iOS/ic_close1.png

315 Bytes
534 Bytes
765 Bytes
319 Bytes
428 Bytes
528 Bytes
428 Bytes
528 Bytes
391 Bytes
616 Bytes
853 Bytes
687 Bytes
1.28 KB
1.87 KB
298 Bytes
369 Bytes
433 Bytes
340 Bytes
415 Bytes
469 Bytes
359 Bytes
488 Bytes
601 Bytes

app/App_Resources/iOS/minus.png

180 Bytes
181 Bytes
181 Bytes

app/App_Resources/iOS/plus.png

209 Bytes
211 Bytes
217 Bytes
111 KB
143 KB
134 KB
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import { ReservationsViewModel, Reservation } from "./reservations-view-model";
2+
import { EventData } from "data/observable";
3+
import { Page, NavigatedData } from "ui/page";
4+
import viewModule = require("ui/core/view");
5+
import { topmost as topmostFrame } from "ui/frame";
6+
import * as navigator from "../../common/navigator";
7+
import dataFormModule = require("nativescript-telerik-ui-pro/dataform");
8+
import { Color } from "color";
9+
import platform = require("platform");
10+
11+
var colorAccent: Color = new Color("#BF3136");
12+
var model: ReservationsViewModel;
13+
var imageWidth: number;
14+
var scale;
15+
16+
export function pageNavigatedTo(args: NavigatedData) {
17+
var screen = platform.screen;
18+
scale = screen.mainScreen.scale;
19+
imageWidth = 56 * scale;
20+
21+
var page = <Page>args.object;
22+
model = <ReservationsViewModel>args.context;
23+
page.bindingContext = model;
24+
}
25+
26+
export function saveChanges(args: EventData) {
27+
var page = <Page>(<viewModule.View>args.object).page;
28+
var dataForm = <dataFormModule.RadDataForm>viewModule.getViewById(page, "reservationForm");
29+
dataForm.commitAll();
30+
31+
if (dataForm.hasValidationErrors()) {
32+
return;
33+
}
34+
35+
if (model.isNew) {
36+
model.reservations.push(model.currentReservation);
37+
}
38+
39+
navigator.navigateBackWithContext(model);
40+
}
41+
42+
export function goBack(args: EventData) {
43+
navigator.navigateBack();
44+
}
45+
46+
export function dfEditorUpdate(data: dataFormModule.DataFormEventData) {
47+
48+
if (data.propertyName == "guests") {
49+
setupEditorGuests(data.editor);
50+
}
51+
52+
if (data.propertyName == "section" || data.propertyName == "table") {
53+
editorSetupPicker(data.editor);
54+
}
55+
56+
if (data.propertyName == "origin") {
57+
var root;
58+
if (data.editor.rootLayout instanceof Function) {
59+
root = data.editor.rootLayout();
60+
} else {
61+
root = data.editor.rootLayout;
62+
}
63+
root.getLayoutParams().setMargins(imageWidth, 0, 0, 0);
64+
}
65+
}
66+
67+
export function dfEditorSetup(data: dataFormModule.DataFormEventData) {
68+
}
69+
70+
export function setupEditorGuests(editor) {
71+
var numberPicker = editor.getEditorView();
72+
numberPicker.setPluralFormatString("%.0f guests");
73+
numberPicker.setSingleFormatString("%.0f guest");
74+
numberPicker.decreaseView().setTextColor(colorAccent.android);
75+
numberPicker.increaseView().setTextColor(colorAccent.android);
76+
}
77+
78+
export function dfGroupUpdate(data: dataFormModule.DataFormEventData) {
79+
if (data.groupName != "TABLE DETAILS") {
80+
return;
81+
}
82+
83+
var androidContext = data.group.rootLayout().getContext();
84+
var bgResourceId = androidContext.getResources().getIdentifier("dataform_table_bg", "drawable", androidContext.getPackageName());
85+
var bgDrawable = androidContext.getResources().getDrawable(bgResourceId);
86+
data.group.rootLayout().setBackground(bgDrawable);
87+
}
88+
89+
export function editorSetupPicker(editor) {
90+
var androidContext = editor.getEditorView().getContext();
91+
var customEditorLayoutId = androidContext.getResources().getIdentifier("reservation_table_spinner_editor", "layout", androidContext.getPackageName());
92+
var customItemLayoutId = androidContext.getResources().getIdentifier("reservation_table_spinner_item", "layout", androidContext.getPackageName());
93+
editor.setSpinnerItemLayoutId(customItemLayoutId);
94+
editor.setEditorLayout(customEditorLayoutId);
95+
}
96+
97+
// Custom Button editor
98+
var buttonValue;
99+
export function editorNeedsView(args) {
100+
var editorView: android.widget.TextView = new android.widget.TextView(args.context);
101+
editorView.setTextColor(colorAccent.android);
102+
var layoutParams = new android.widget.FrameLayout.LayoutParams(-2, -2);
103+
layoutParams.setMargins(imageWidth, 0, 0, 0);
104+
editorView.setLayoutParams(layoutParams);
105+
var editorPadding = 4 * scale;
106+
editorView.setPadding(editorPadding, editorPadding, editorPadding, editorPadding);
107+
108+
editorView.setOnClickListener(new android.view.View.OnClickListener({
109+
onClick(view: android.view.View) {
110+
handleTap(view, args.object);
111+
}
112+
}));
113+
args.view = editorView;
114+
}
115+
116+
export function editorHasToApplyValue(args) {
117+
updateEditorValue(args.view, args.value);
118+
}
119+
120+
export function editorNeedsValue(args) {
121+
args.value = buttonValue;
122+
}
123+
124+
export function updateEditorValue(editorView, value) {
125+
buttonValue = value;
126+
var buttonText = buttonValue ? "CANCELLED" : "CANCEL RESERVATION";
127+
editorView.setText(buttonText);
128+
}
129+
130+
export function handleTap(editorView, editor) {
131+
var newValue = !buttonValue;
132+
updateEditorValue(editorView, newValue);
133+
editor.notifyValueChanged();
134+
}

0 commit comments

Comments
 (0)