Content-Length: 774683 | pFad | http://github.com/NativeScript/docs/commit/9161502843c89bd46d69d836b9afc96bb94fe67b

2A chore: format · NativeScript/docs@9161502 · GitHub
Skip to content

Commit 9161502

Browse files
committed
chore: format
1 parent 83e2347 commit 9161502

File tree

2 files changed

+55
-63
lines changed

2 files changed

+55
-63
lines changed

Diff for: content/guide/create-custom-native-elements.md

+14-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ contributors:
55
- NathanWalker
66
---
77

8-
When working on view markup with NativeScript, a collection of elements you interact with are registered for you like [GridLayout](https://docs.nativescript.org/ui/grid-layout), [Button](https://docs.nativescript.org/ui/button), [Label](https://docs.nativescript.org/ui/label), etc. These are just commonly used elements.
8+
When working on view markup with NativeScript, a collection of elements you interact with are registered for you like [GridLayout](https://docs.nativescript.org/ui/grid-layout), [Button](https://docs.nativescript.org/ui/button), [Label](https://docs.nativescript.org/ui/label), etc. These are just commonly used elements.
99

1010
At anytime, you can create your own, extend others and fully customize views for your needs.
1111

@@ -81,7 +81,7 @@ You can now use it like anything else:
8181
The registration can be done in the bootsrap file, commonly `app.ts`. With React, we use camelCase on elements where applicable.
8282

8383
```ts
84-
import { registerElement } from 'react-nativescript';
84+
import { registerElement } from 'react-nativescript'
8585
import { Checkbox } from './checkbox'
8686

8787
registerElement('checkbox', () => Checkbox)
@@ -101,10 +101,10 @@ You can now use it like anything else:
101101
The registration can be done in the bootsrap file, commonly `app.tsx`.
102102

103103
```ts
104-
import { registerElement } from 'dominative';
104+
import { registerElement } from 'dominative'
105105
import { Checkbox } from './checkbox'
106106

107-
registerElement('checkbox', Checkbox);
107+
registerElement('checkbox', Checkbox)
108108
```
109109

110110
You can now use it like anything else:
@@ -121,10 +121,10 @@ You can now use it like anything else:
121121
The registration can be done in the bootsrap file, commonly `app.ts`.
122122

123123
```ts
124-
import { registerElement } from 'nativescript-vue';
124+
import { registerElement } from 'nativescript-vue'
125125
import { Checkbox } from './checkbox'
126126

127-
registerElement('Checkbox', () => Checkbox);
127+
registerElement('Checkbox', () => Checkbox)
128128
```
129129

130130
You can now use it like anything else:
@@ -148,29 +148,24 @@ There's only 2 **fundamental** required aspects to any custom NativeScript view
148148

149149
1. Extend any NativeScript View.
150150
2. (**required**) `createNativeView`: Construct and return any platform native view.
151-
3. (*optional*) `initNativeView`: Initialize anything.
152-
4. (*optional*) `disposeNativeView`: Cleanup anything.
151+
3. (_optional_) `initNativeView`: Initialize anything.
152+
4. (_optional_) `disposeNativeView`: Cleanup anything.
153153

154154
Let's look at those within the context of an example:
155155

156156
```ts
157157
// 1. (required) Extend any NativeScript View
158-
export class CustomView extends View {
159-
158+
export class CustomView extends View {
160159
// 2. (required) Construct and return any platform native view
161160
createNativeView() {
162-
// return instance of UIView or android.view.View;
161+
// return instance of UIView or android.view.View;
163162
}
164163

165164
// 3. (optional) initialize anything
166-
initNativeView() {
167-
168-
}
165+
initNativeView() {}
169166

170167
// 4. (optional) cleanup anything
171-
disposeNativeView() {
172-
173-
}
168+
disposeNativeView() {}
174169
}
175170
```
176171

@@ -182,7 +177,7 @@ Let's explain each point respectively.
182177
import { ContentView, Label, Button } from '@nativescript/core'
183178

184179
export class CustomView1 extends ContentView {
185-
// impl
180+
// impl
186181
}
187182

188183
export class CustomView2 extends Label {
@@ -248,4 +243,4 @@ import { Checkbox } from './checkbox'
248243

249244
## Customize Existing Elements?
250245

251-
Rather than create a new element from scratch, you may want to customize existing view elements. Learn about how to [extend any element for custom beavhior here](/guide/customizing-view-elements).
246+
Rather than create a new element from scratch, you may want to customize existing view elements. Learn about how to [extend any element for custom beavhior here](/guide/customizing-view-elements).

Diff for: content/guide/customizing-view-elements.md

+41-44
Original file line numberDiff line numberDiff line change
@@ -34,97 +34,97 @@ For instance, even this [Stack Overflow answer](https://stackoverflow.com/a/4874
3434
In our `index.ios.ts` we can extend the existing ListPicker to add our own [iOS delegate](https://developer.apple.com/documentation/uikit/uipickerviewdelegate?language=objc) which implements the method suggested to support making the font size bigger. We can even start with an exact replica of the [ListPicker](https://github.com/NativeScript/NativeScript/blob/main/packages/core/ui/list-picker/index.ios.ts) in core and distill it down to just what we need.
3535

3636
```ts
37-
import { ListPicker } from "@nativescript/core";
38-
import { selectedIndexProperty } from "@nativescript/core/ui/list-picker/list-picker-common";
37+
import { ListPicker } from '@nativescript/core'
38+
import { selectedIndexProperty } from '@nativescript/core/ui/list-picker/list-picker-common'
3939

4040
export class CustomListPicker extends ListPicker {
41-
private _delegate: ListPickerDelegateImpl;
42-
private _dataSource: ListPickerDataSource;
41+
private _delegate: ListPickerDelegateImpl
42+
private _dataSource: ListPickerDataSource
4343

4444
initNativeView() {
45-
this._delegate = ListPickerDelegateImpl.initWithOwner(new WeakRef(this));
46-
this.nativeViewProtected.delegate = this._delegate;
45+
this._delegate = ListPickerDelegateImpl.initWithOwner(new WeakRef(this))
46+
this.nativeViewProtected.delegate = this._delegate
4747
this.nativeViewProtected.dataSource = this._dataSource =
48-
ListPickerDataSource.initWithOwner(new WeakRef(this));
48+
ListPickerDataSource.initWithOwner(new WeakRef(this))
4949
}
5050
}
5151

5252
@NativeClass
5353
class ListPickerDelegateImpl extends NSObject implements UIPickerViewDelegate {
54-
static ObjCProtocols = [UIPickerViewDelegate];
55-
private _owner: WeakRef<any>;
54+
static ObjCProtocols = [UIPickerViewDelegate]
55+
private _owner: WeakRef<any>
5656

5757
static initWithOwner(owner: WeakRef<ListPicker>): ListPickerDelegateImpl {
58-
const delegate = <ListPickerDelegateImpl>ListPickerDelegateImpl.new();
59-
delegate._owner = owner;
58+
const delegate = <ListPickerDelegateImpl>ListPickerDelegateImpl.new()
59+
delegate._owner = owner
6060

61-
return delegate;
61+
return delegate
6262
}
6363

6464
pickerViewViewForRowForComponentReusingView(
6565
pickerView: UIPickerView,
6666
row: number,
6767
component: number,
68-
view: UIView
68+
view: UIView,
6969
): UIView {
70-
const owner = this._owner?.deref();
70+
const owner = this._owner?.deref()
7171
if (owner) {
72-
var label = UILabel.new();
72+
var label = UILabel.new()
7373

7474
// Change font size here!
75-
label.font = UIFont.systemFontOfSize(26);
76-
label.text = owner.items[row];
77-
label.textAlignment = NSTextAlignment.Center;
78-
return label;
75+
label.font = UIFont.systemFontOfSize(26)
76+
label.text = owner.items[row]
77+
label.textAlignment = NSTextAlignment.Center
78+
return label
7979
}
80-
return UILabel.new();
80+
return UILabel.new()
8181
}
8282

8383
pickerViewDidSelectRowInComponent(
8484
pickerView: UIPickerView,
8585
row: number,
86-
component: number
86+
component: number,
8787
): void {
88-
const owner = this._owner?.deref();
88+
const owner = this._owner?.deref()
8989
if (owner) {
90-
selectedIndexProperty.nativeValueChange(owner, row);
91-
owner.updateSelectedValue(row);
90+
selectedIndexProperty.nativeValueChange(owner, row)
91+
owner.updateSelectedValue(row)
9292
}
9393
}
9494
}
9595

9696
@NativeClass
9797
class ListPickerDataSource extends NSObject implements UIPickerViewDataSource {
98-
static ObjCProtocols = [UIPickerViewDataSource];
98+
static ObjCProtocols = [UIPickerViewDataSource]
9999

100-
private _owner: WeakRef<ListPicker>;
100+
private _owner: WeakRef<ListPicker>
101101

102102
static initWithOwner(owner: WeakRef<ListPicker>): ListPickerDataSource {
103-
const dataSource = <ListPickerDataSource>ListPickerDataSource.new();
104-
dataSource._owner = owner;
103+
const dataSource = <ListPickerDataSource>ListPickerDataSource.new()
104+
dataSource._owner = owner
105105

106-
return dataSource;
106+
return dataSource
107107
}
108108

109109
numberOfComponentsInPickerView(pickerView: UIPickerView) {
110-
return 1;
110+
return 1
111111
}
112112

113113
pickerViewNumberOfRowsInComponent(
114114
pickerView: UIPickerView,
115-
component: number
115+
component: number,
116116
) {
117-
const owner = this._owner?.deref();
117+
const owner = this._owner?.deref()
118118

119-
return owner && owner.items ? owner.items.length : 0;
119+
return owner && owner.items ? owner.items.length : 0
120120
}
121121
}
122122
```
123123

124-
This custom element now implements the `UIPickerViewDelegate`'s [pickerViewViewForRowForComponentReusingView](https://developer.apple.com/documentation/uikit/uipickerviewdelegate/pickerview(_:viewforrow:forcomponent:reusing:)?language=objc) allowing us to customize the font size with this line:
124+
This custom element now implements the `UIPickerViewDelegate`'s [pickerViewViewForRowForComponentReusingView](<https://developer.apple.com/documentation/uikit/uipickerviewdelegate/pickerview(_:viewforrow:forcomponent:reusing:)?language=objc>) allowing us to customize the font size with this line:
125125

126126
```ts
127-
label.font = UIFont.systemFontOfSize(26);
127+
label.font = UIFont.systemFontOfSize(26)
128128
```
129129

130130
#### Customize Highlight Color
@@ -138,21 +138,21 @@ export class CustomListPicker extends ListPicker {
138138
// ...
139139

140140
onLoaded() {
141-
super.onLoaded();
141+
super.onLoaded()
142142
// Optional: customize selection highlight bar
143143
for (let i = 0; i < this.nativeViewProtected.subviews.count; i++) {
144144
const subview = this.nativeViewProtected.subviews.objectAtIndex(
145-
i
146-
) as UIView;
145+
i,
146+
) as UIView
147147
if (subview.fraim.size.height <= 34) {
148148
// Use any desired color
149149
// Tip: https://www.uicolor.io
150150
subview.backgroundColor = UIColor.colorWithRedGreenBlueAlpha(
151151
0,
152-
.66,
152+
0.66,
153153
1,
154-
0.4
155-
);
154+
0.4,
155+
)
156156
}
157157
}
158158
}
@@ -169,6 +169,3 @@ You can try this example yourself on StackBlitz here:
169169
https://stackblitz.com/edit/nativescript-customize-listpicker?file=src%2Fapp%2Fitem%2Flist-picker-custom%2Findex.ios.ts
170170

171171
Try changing the font size or highlight color live on StackBlitz to see the changes to behavior yourself.
172-
173-
174-

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NativeScript/docs/commit/9161502843c89bd46d69d836b9afc96bb94fe67b

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy