diff --git a/native/components/user-list-user.react.js b/native/components/user-list-user.react.js index 815aefacf..68f148bcc 100644 --- a/native/components/user-list-user.react.js +++ b/native/components/user-list-user.react.js @@ -1,105 +1,94 @@ // @flow -import PropTypes from 'prop-types'; import * as React from 'react'; import { Text, Platform, Alert } from 'react-native'; -import { type UserListItem, userListItemPropType } from 'lib/types/user-types'; -import { connect } from 'lib/utils/redux-utils'; +import type { UserListItem } from 'lib/types/user-types'; -import type { AppState } from '../redux/redux-setup'; -import { - type Colors, - colorsPropType, - colorsSelector, - styleSelector, -} from '../themes/colors'; +import { type Colors, useColors, useStyles } from '../themes/colors'; import type { TextStyle } from '../types/styles'; import Button from './button.react'; import { SingleLine } from './single-line.react'; // eslint-disable-next-line no-unused-vars const getUserListItemHeight = (item: UserListItem) => { // TODO consider parent thread notice return Platform.OS === 'ios' ? 31.5 : 33.5; }; +type BaseProps = {| + +userInfo: UserListItem, + +onSelect: (userID: string) => void, + +textStyle?: TextStyle, +|}; type Props = {| - userInfo: UserListItem, - onSelect: (userID: string) => void, - textStyle?: TextStyle, + ...BaseProps, // Redux state - colors: Colors, - styles: typeof styles, + +colors: Colors, + +styles: typeof unboundStyles, |}; class UserListUser extends React.PureComponent { - static propTypes = { - userInfo: userListItemPropType.isRequired, - onSelect: PropTypes.func.isRequired, - textStyle: Text.propTypes.style, - colors: colorsPropType.isRequired, - styles: PropTypes.objectOf(PropTypes.object).isRequired, - }; - render() { const { userInfo } = this.props; let notice = null; if (userInfo.notice) { notice = {userInfo.notice}; } const { modalIosHighlightUnderlay: underlayColor } = this.props.colors; return ( ); } onSelect = () => { const { userInfo } = this.props; if (!userInfo.alertText) { this.props.onSelect(userInfo.id); return; } Alert.alert('Not a friend', userInfo.alertText, [{ text: 'OK' }], { cancelable: true, }); }; } -const styles = { +const unboundStyles = { button: { alignItems: 'center', flexDirection: 'row', justifyContent: 'space-between', }, notice: { color: 'modalForegroundSecondaryLabel', fontStyle: 'italic', }, text: { color: 'modalForegroundLabel', flex: 1, fontSize: 16, paddingHorizontal: 12, paddingVertical: 6, }, }; -const stylesSelector = styleSelector(styles); -const WrappedUserListUser = connect((state: AppState) => ({ - colors: colorsSelector(state), - styles: stylesSelector(state), -}))(UserListUser); +const ConnectedUserListUser = React.memo( + function ConnectedUserListUser(props: BaseProps) { + const colors = useColors(); + const styles = useStyles(unboundStyles); + return ; + }, +); -export { WrappedUserListUser as UserListUser, getUserListItemHeight }; +export { ConnectedUserListUser as UserListUser, getUserListItemHeight };