You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/guide/data-binding.md
+36-23
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@ There are various ways to manage data flow, often referred to as data bindings:
19
19
```xml
20
20
<Labeltext="{{ name }}" />
21
21
```
22
+
22
23
```ts
23
24
exportclassHelloWorldModelextendsObservable {
24
25
name ="John Doe"
@@ -27,14 +28,16 @@ export class HelloWorldModel extends Observable {
27
28
28
29
}
29
30
```
31
+
30
32
-**One-way (to Model) data binding** - Binding which updates the model in relation to some action in the UI. The best example for this is a [tap](/guide/ui-components/gestures-in-nativescript#tap-gesture-in-nativescript) event.
31
33
32
34
```xml
33
35
<Buttontext="Submit"tap="{{ onTap }}"/>
34
36
```
37
+
35
38
```ts
36
39
exportclassHelloWorldModelextendsObservable {
37
-
40
+
38
41
onTap(args:EventData){
39
42
40
43
}
@@ -49,6 +52,7 @@ export class HelloWorldModel extends Observable {
49
52
```xml
50
53
<TextFieldtext="{{ name }}"/>
51
54
```
55
+
52
56
```ts
53
57
exportclassHelloWorldModelextendsObservable {
54
58
name ="John Doe"
@@ -60,12 +64,13 @@ export class HelloWorldModel extends Observable {
60
64
61
65
## Accessing parent bindingContext
62
66
63
-
A parent and a child UI components can have different binding contexts and the child component might need to bind its property to a source property in its parent's **bindingContext**.
67
+
A parent and a child UI components can have different binding contexts and the child component might need to bind its property to a source property in its parent's **bindingContext**.
64
68
65
69
<!-- TODO: fix links -->
66
-
Generally, the binding context is inheritable, but not when the components are created dynamically based on some data source. For example, [ListView]() creates its child items based on an `itemТemplate`, which describes what the ListView component will look like. When this component is added to the visual tree, for binding context it gets an element from a `ListView` items array (with the corresponding index).
67
70
68
-
This process creates a new binding context chain for the child item and its inner UI components. So, the inner UI component cannot access the binding context of the `ListView`. In order to solve this problem, NativeScript binding infrastructure has two special keywords:
71
+
Generally, the binding context is inheritable, but not when the components are created dynamically based on some data source. For example, [ListView]() creates its child items based on an `itemТemplate`, which describes what the ListView component will look like. When this component is added to the visual tree, for binding context it gets an element from a `ListView` items array (with the corresponding index).
72
+
73
+
This process creates a new binding context chain for the child item and its inner UI components. So, the inner UI component cannot access the binding context of the `ListView`. In order to solve this problem, NativeScript binding infrastructure has two special keywords:
69
74
70
75
-`$parent` : denotes the binding context of the direct parent visual component
71
76
-`$parents` : can be used as an array (with a number or string index). This gives you the option to choose either N levels of UI nesting or get a parent UI component with a given type.
@@ -85,22 +90,23 @@ NativeScript supports the following polymorphic binding expressions:
85
90
### Property access
86
91
87
92
To access a value stored in an object property of the bindingContext, use the propert access expression:
## Calling Objective-C/Swift methods with multiple arguments
107
107
108
-
Consider the following `NSMutableArray` selector: `replaceObjectsInRange:withObjectsFromArray:range:`.
109
-
110
-
In JavaScript it is represented by: `replaceObjectsInRangeWithObjectsFromArrayRange(objectsToRange, sourceArray, sourceRange)` (argument names are arbitrary).
108
+
Consider the following `NSMutableArray` selector: `replaceObjectsInRange:withObjectsFromArray:range:`.
111
109
110
+
In JavaScript it is represented by: `replaceObjectsInRangeWithObjectsFromArrayRange(objectsToRange, sourceArray, sourceRange)` (argument names are arbitrary).
112
111
113
112
In Objective-C, when generating the function name for a method, it follows a convention of appending the names of the arguments defined by the Objective-C selector. The function name starts with a lowercase letter for the first argument and appends subsequent arguments with a capital letter.
114
113
@@ -123,7 +122,8 @@ For an example of how to extend an Objective-C/Swift class, have a look at [Exte
123
122
The below code shows how to convert a JavaScript array to a `CGFloat` array to pass it to an Objective-C method expecting `CGFloat` as an argument:
@@ -157,30 +157,31 @@ On the other hand, any API that expects a `NSNull`, `NSNumber`, `NSString` or `N
157
157
### Converting numeric types
158
158
159
159
```ts
160
-
console.log(`pow(2.5, 3) = ${Math.pow(2.5, 3)}`);
160
+
console.log(`pow(2.5, 3) = ${Math.pow(2.5, 3)}`)
161
161
```
162
+
162
163
The iOS Runtime converts JavaScript number literals to native doubles and utilizes the native pow(double x, double y) function. The resulting native integer is automatically converted back to a JavaScript number and then passed as an argument to console.log() for output..
`Button title` is converted to `NSString` and the returned `NSString` is converted to JavaScript `string`.
172
174
173
175
### Converting boolean
174
176
175
177
```ts
176
-
let str =NSString.stringWithString('YES');
177
-
let isTrue =str.boolValue;
178
+
let str =NSString.stringWithString('YES')
179
+
let isTrue =str.boolValue
178
180
```
179
181
180
182
## Objective-C Protocols
181
183
182
-
Protocols in Objective-C serve a similar purpose as interfaces in other programming languages. They define a blueprint or contract that specifies the members (methods, properties, etc.) that a class should implement. Protocols are exposed as empty objects in JavaScript. Protocols are usually only referenced when [subclassing](/guide/subclassing/extending-classes-and-conforming-protocols-ios) an Objective-C class or when checking whether an object or class conforms to a protocol.
183
-
184
+
Protocols in Objective-C serve a similar purpose as interfaces in other programming languages. They define a blueprint or contract that specifies the members (methods, properties, etc.) that a class should implement. Protocols are exposed as empty objects in JavaScript. Protocols are usually only referenced when [subclassing](/guide/subclassing/extending-classes-and-conforming-protocols-ios) an Objective-C class or when checking whether an object or class conforms to a protocol.
To implement Objective-C/Swift protocols in NativeScript, hava look at [Conforming to Objective-C/Swift protocols in NativeScript](/guide/subclassing/extending-classes-and-conforming-protocols-ios#conforming-to-objective-c-swift-protocols-in-nativescript)
Copy file name to clipboardExpand all lines: content/guide/ios-runtime-types.md
+10-13
Original file line number
Diff line number
Diff line change
@@ -4,43 +4,40 @@ title: iOS Runtime Types
4
4
5
5
NativeScript provides the `interop` module for working with native C types, pointers, pointer arithmetic and memory.
6
6
7
-
8
7
<!-- TODO: Add examples -->
9
8
10
9
## Using interop
11
10
12
11
### Creating a pointer
13
12
14
-
The `Pointer` type allows you to represent a void*.
13
+
The `Pointer` type allows you to represent a void\*.
15
14
16
15
#### Using the constructor
17
16
18
17
To create a new pointer with the given offset, use the constructor:
19
18
20
19
```ts
21
-
const interop1 =newinterop.Pointer(34)
20
+
const interop1 =newinterop.Pointer(34)
22
21
```
23
22
24
23
#### Creating a pointer by adding an offset from an existing pointer
25
24
26
-
```ts
25
+
```ts
27
26
const interop2 =interop1.add(4)
28
-
```
27
+
```
29
28
30
29
#### Creating a pointer by removing an offset to an existing pointer
31
30
32
-
```ts
31
+
```ts
33
32
const interop3 =interop1.subtract(3)
34
-
```
33
+
```
35
34
36
35
## interop API
37
36
38
37
### Pointer.toNumber()
39
38
40
39
```ts
41
-
42
40
pointerInstance.toNumber()
43
-
44
41
```
45
42
46
43
Converts the value of a `Pointer` instance to a number.
@@ -78,6 +75,7 @@ Releases the memory of the specified unadopted pointer.
78
75
interop.sizeof(type: any): number
79
76
80
77
```
78
+
81
79
Returns the size of the provided type. The `type` can be: a class constructor (of Objective-C interface), an instance (wrapper of Objective-C interface), struct constructor, struct instance, reference, protocol, function (for c function), fundamental types
82
80
83
81
---
@@ -118,7 +116,6 @@ Wraps an NSData instance in an ArrayBuffer.
118
116
119
117
---
120
118
121
-
122
119
### new Reference(value)
123
120
124
121
Creates a new reference around a JavaScript `value`. The native representation of the type will be determined during the first time the Reference is used in an operation involving marshalling.
@@ -143,7 +140,6 @@ Creates a function reference that can be marshalled as a native function pointer
143
140
144
141
### interop types
145
142
146
-
147
143
- "void": Type\<void\>
148
144
- bool: Type\<boolean\>
149
145
- int8: Type\<number\>
@@ -165,7 +161,7 @@ Creates a function reference that can be marshalled as a native function pointer
165
161
- "class": Type\<any\>
166
162
- selector: Type\<string\>
167
163
168
-
----
164
+
---
169
165
170
166
### new StructType()
171
167
@@ -180,11 +176,12 @@ Create a new instance of the struct and initialize it from the fields of the pro
Copy file name to clipboardExpand all lines: content/guide/metadata.md
+2-1
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,9 @@ Missing metadata entities could result in bugs at runtime. For example, if a nat
75
75
- On Android they are located in `platforms/android/build-tools/buildMetadata.log`
76
76
77
77
For each global symbol that is discovered by the generator, there should be a line providing information whether it was included in the metadata or not, and which rules or what exception caused this. Examples:
78
+
78
79
<!-- TODO: An example of the following -->
80
+
79
81
-`verbose: Blacklisted kCFBuddhistCalendar from CoreFoundation.CFLocale (disabled by 'CoreFoundation*:*')` - when there are no whitelist rules a blacklisted symbol will show only the rule which disabled it
80
82
-`verbose: Blacklisted NSString from Foundation.NSString` - when there is at least one whitelist rule, some blacklisted symbols will not specify a rule. This means that the symbol didn't match any of the whitelist rules.
81
83
-`verbose: Blacklisted PHImageContentModeDefault from Photos.PhotosTypes (enabled by 'Photos.PhotosTypes:*', disabled by 'Photos.PhotosTypes:PHImageContentMode*')`, `verbose: Blacklisted String from java.lang (enabled by java.lang:*, disabled by java.lang:String)` - a blacklisted entry which matches both a whitelist rule and a blacklist rule will specify both.
@@ -131,4 +133,3 @@ if (android.os.Build.VERSION.SDK_INT >= 21) {
131
133
## iOS Metadata
132
134
133
135
This is our own custom data format for listing the iOS APIs we are aware of and can handle. It stores the minimal required information and provides a small size and highly efficient read access. iOS supports type introspection to some extent but along with the C APIs embedded all the way in the native APIs we had to store a lot of extra information. The Metadata is pre-generated at compile time from the SDK header files and embedded in the app package (ipa).
0 commit comments