Skip to content
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

refactor(fscomponents): FLAGSHIP-63 - Updating To Function Component #998

Merged
merged 1 commit into from
Jan 24, 2020
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
57 changes: 28 additions & 29 deletions packages/fscomponents/src/components/SelectableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React, { FunctionComponent, memo } from 'react';
import {
AccessibilityRole,
StyleProp,
Expand Down Expand Up @@ -54,41 +54,40 @@ const S = StyleSheet.create({
}
});

export class SelectableRow extends Component<SelectableRowProps> {
renderCheckMark = () => {
if (this.props.renderCheckMark) {
return this.props.renderCheckMark();
export const SelectableRow: FunctionComponent<SelectableRowProps> =
memo((props): JSX.Element => {
const renderCheckMark = () => {
if (props.renderCheckMark) {
return props.renderCheckMark();
}

return (
<View style={S.marker}>
<View style={[S.markerIcon, this.props.markerIconStyle]} />
<View style={[S.markerIcon, props.markerIconStyle]} />
</View>
);
}
};

renderUncheckMark = () => {
if (this.props.renderUncheckMark) {
return this.props.renderUncheckMark();
const renderUncheckMark = () => {
if (props.renderUncheckMark) {
return props.renderUncheckMark();
}
return null;
}
};

render(): JSX.Element {
return (
<TouchableOpacity
style={[S.row, this.props.style]}
onPress={this.props.onPress}
accessibilityLabel={this.props.accessibilityLabel || this.props.title}
accessibilityRole={this.props.accessibilityRole || 'button'}
>
<Text style={[S.rowText, this.props.textStyle]}>
{this.props.title}
</Text>
{this.props.selected
? this.renderCheckMark()
: this.renderUncheckMark()}
</TouchableOpacity>
);
}
}
return (
<TouchableOpacity
style={[S.row, props.style]}
onPress={props.onPress}
accessibilityLabel={props.accessibilityLabel || props.title}
accessibilityRole={props.accessibilityRole || 'button'}
>
<Text style={[S.rowText, props.textStyle]}>
{props.title}
</Text>
{props.selected
? renderCheckMark()
: renderUncheckMark()}
</TouchableOpacity>
);
});