Skip to content

Commit df7ddb8

Browse files
authored
Migrate our ExampleScreenPresenter to TS (#1658)
1 parent ffafba5 commit df7ddb8

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

demo/src/screens/ExampleScreenPresenter.js renamed to demo/src/screens/ExampleScreenPresenter.tsx

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,53 @@ import {
1010
RadioGroup,
1111
Slider,
1212
SegmentedControl,
13+
SegmentedControlItemProps,
1314
Text,
15+
TextProps,
1416
View
1517
} from 'react-native-ui-lib';
1618

17-
export function renderHeader(title, others) {
19+
interface RadioGroupOptions {
20+
isRow?: boolean;
21+
afterValueChanged?: () => void;
22+
useValueAsLabel?: boolean;
23+
}
24+
25+
export function renderHeader(title: string, others: TextProps) {
1826
return (
1927
<Text text30 grey10 {...others}>
2028
{title}
2129
</Text>
2230
);
2331
}
2432

25-
export function renderBooleanOption(title, key) {
33+
export function renderBooleanOption(title: string, key: string) {
34+
// @ts-ignore
2635
const value = this.state[key];
2736
return (
2837
<View row centerV spread marginB-s4 key={key}>
29-
<Text flex>
30-
{title}
31-
</Text>
38+
<Text flex>{title}</Text>
3239
<Switch
3340
useCustomTheme
3441
key={key}
35-
textID={key}
42+
testID={key}
3643
value={value}
44+
// @ts-ignore
3745
onValueChange={value => this.setState({[key]: value})}
3846
/>
3947
</View>
4048
);
4149
}
4250

43-
export function renderBooleanGroup(title, options) {
51+
export function renderBooleanGroup(title: string, options: string[]) {
4452
return (
4553
<View marginB-s2>
4654
<Text text70M marginB-s2>
4755
{title}
4856
</Text>
4957
<View row style={styles.rowWrap}>
5058
{_.map(options, key => {
59+
// @ts-ignore
5160
const value = this.state[key];
5261
return (
5362
<View spread centerH row key={key}>
@@ -57,6 +66,7 @@ export function renderBooleanGroup(title, options) {
5766
key={key}
5867
testID={key}
5968
value={value}
69+
// @ts-ignore
6070
onValueChange={value => this.setState({[key]: value})}
6171
/>
6272
<Text text70 marginR-s3 marginB-s2>
@@ -70,7 +80,11 @@ export function renderBooleanGroup(title, options) {
7080
);
7181
}
7282

73-
export function renderRadioGroup(title, key, options, {isRow, afterValueChanged, useValueAsLabel} = {}) {
83+
export function renderRadioGroup(title: string,
84+
key: string,
85+
options: object,
86+
{isRow, afterValueChanged, useValueAsLabel}: RadioGroupOptions = {}) {
87+
// @ts-ignore
7488
const value = this.state[key];
7589
return (
7690
<View marginB-s2>
@@ -83,6 +97,7 @@ export function renderRadioGroup(title, key, options, {isRow, afterValueChanged,
8397
row={isRow}
8498
style={isRow && styles.rowWrap}
8599
initialValue={value}
100+
// @ts-ignore
86101
onValueChange={value => this.setState({[key]: value}, afterValueChanged)}
87102
>
88103
{_.map(options, (value, key) => {
@@ -103,23 +118,28 @@ export function renderRadioGroup(title, key, options, {isRow, afterValueChanged,
103118
);
104119
}
105120

106-
export function renderColorOption(title,
107-
key,
121+
export function renderColorOption(title: string,
122+
key: string,
108123
colors = ['transparent', Colors.blue30, Colors.grey10, Colors.yellow30, Colors.green30, Colors.purple30]) {
124+
// @ts-ignore
109125
const value = this.state[key];
110126
return (
111127
<View marginV-s2>
112128
<Text text70M>{title}</Text>
113129
<ColorPalette
114130
value={value}
115131
colors={colors}
132+
// @ts-ignore
116133
onValueChange={value => this.setState({[key]: value === 'transparent' ? undefined : value})}
117134
/>
118135
</View>
119136
);
120137
}
121138

122-
export function renderSliderOption(title, key, {min = 0, max = 10, step = 1, initial = 0, sliderText = ''}) {
139+
export function renderSliderOption(title: string,
140+
key: string,
141+
{min = 0, max = 10, step = 1, initial = 0, sliderText = ''}) {
142+
// @ts-ignore
123143
const value = this.state[key] || initial;
124144
return (
125145
<View marginV-s2>
@@ -134,6 +154,7 @@ export function renderSliderOption(title, key, {min = 0, max = 10, step = 1, ini
134154
minimumValue={min}
135155
maximumValue={max}
136156
step={step}
157+
// @ts-ignore
137158
onValueChange={value => this.setState({[key]: value})}
138159
/>
139160
<Text marginL-s4 text70 style={styles.text}>
@@ -145,7 +166,8 @@ export function renderSliderOption(title, key, {min = 0, max = 10, step = 1, ini
145166
);
146167
}
147168

148-
export function renderMultipleSegmentOptions(title, key, options) {
169+
export function renderMultipleSegmentOptions(title: string, key: string, options: (SegmentedControlItemProps & {value: any})[]) {
170+
// @ts-ignore
149171
const value = this.state[key];
150172
const index = _.findIndex(options, {value});
151173

@@ -155,6 +177,7 @@ export function renderMultipleSegmentOptions(title, key, options) {
155177
<SegmentedControl
156178
initialIndex={index}
157179
segments={options}
180+
// @ts-ignore
158181
onChangeIndex={index => this.setState({[key]: options[index].value})}
159182
/>
160183
</View>

demo/src/screens/componentScreens/HintsScreen.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import _ from 'lodash';
22
import React, {Component} from 'react';
33
import {Alert} from 'react-native';
44
import {Colors, View, Text, Hint, Button, Assets, Incubator} from 'react-native-ui-lib';
5-
// @ts-expect-error
65
import {renderMultipleSegmentOptions, renderBooleanOption} from '../ExampleScreenPresenter';
76

87
const settingsIcon = require('../../assets/icons/settings.png');

0 commit comments

Comments
 (0)