Skip to content

ExampleScreenPresenter - improve renderBooleanOption #2037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions demo/src/screens/ExampleScreenPresenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ interface RadioGroupOptions {
useValueAsLabel?: boolean;
}

interface BooleanGroupOptions {
spread?: boolean;
afterValueChanged?: () => void;
}

export function renderHeader(title: string, others?: TextProps) {
return (
<Text text30 $textDefault {...others}>
Expand All @@ -30,19 +35,19 @@ export function renderHeader(title: string, others?: TextProps) {
);
}

export function renderBooleanOption(title: string, key: string) {
export function renderBooleanOption(title: string, key: string, {spread, afterValueChanged}: BooleanGroupOptions = {spread: true}) {
// @ts-ignore
const value = this.state[key];
return (
<View row centerV spread marginB-s4 key={key}>
<Text $textDefault flex>{title}</Text>
<View row centerV spread={spread} marginB-s4 key={key}>
<Text $textDefault flex={spread} marginR-s4={!spread}>{title}</Text>
<Switch
useCustomTheme
key={key}
testID={key}
value={value}
// @ts-ignore
onValueChange={value => this.setState({[key]: value})}
onValueChange={value => this.setState({[key]: value}, afterValueChanged)}
/>
</View>
);
Expand Down