Changeset View
Changeset View
Standalone View
Standalone View
native/chat/message-list-header-title.react.js
// @flow | // @flow | ||||
import { HeaderTitle } from '@react-navigation/stack'; | import { HeaderTitle } from '@react-navigation/stack'; | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { View, Platform } from 'react-native'; | import { View, Platform } from 'react-native'; | ||||
import Icon from 'react-native-vector-icons/Ionicons'; | import Icon from 'react-native-vector-icons/Ionicons'; | ||||
import { | |||||
threadIsPending, | |||||
threadMembersWithoutAddedAshoat, | |||||
} from 'lib/shared/thread-utils'; | |||||
import type { ThreadInfo } from 'lib/types/thread-types'; | import type { ThreadInfo } from 'lib/types/thread-types'; | ||||
import { firstLine } from 'lib/utils/string-utils'; | import { firstLine } from 'lib/utils/string-utils'; | ||||
import Button from '../components/button.react'; | import Button from '../components/button.react'; | ||||
import { ThreadSettingsRouteName } from '../navigation/route-names'; | import { ThreadSettingsRouteName } from '../navigation/route-names'; | ||||
import { useStyles } from '../themes/colors'; | import { useStyles } from '../themes/colors'; | ||||
import type { ChatNavigationProp } from './chat.react'; | import type { ChatNavigationProp } from './chat.react'; | ||||
type BaseProps = { | type BaseProps = { | ||||
+threadInfo: ThreadInfo, | +threadInfo: ThreadInfo, | ||||
+searching: boolean | void, | |||||
+navigate: $PropertyType<ChatNavigationProp<'MessageList'>, 'navigate'>, | +navigate: $PropertyType<ChatNavigationProp<'MessageList'>, 'navigate'>, | ||||
+isSearchEmpty: boolean, | |||||
+areSettingsEnabled: boolean, | |||||
}; | }; | ||||
type Props = { | type Props = { | ||||
...BaseProps, | ...BaseProps, | ||||
+styles: typeof unboundStyles, | +styles: typeof unboundStyles, | ||||
}; | }; | ||||
class MessageListHeaderTitle extends React.PureComponent<Props> { | class MessageListHeaderTitle extends React.PureComponent<Props> { | ||||
render() { | render() { | ||||
const isSearchEmpty = | |||||
this.props.searching && | |||||
threadMembersWithoutAddedAshoat(this.props.threadInfo).length === 1; | |||||
let icon, fakeIcon; | let icon, fakeIcon; | ||||
const areSettingsDisabled = | if (Platform.OS === 'ios' && this.props.areSettingsEnabled) { | ||||
threadIsPending(this.props.threadInfo.id) || isSearchEmpty; | |||||
if (Platform.OS === 'ios' && !areSettingsDisabled) { | |||||
icon = ( | icon = ( | ||||
<Icon | <Icon | ||||
name="ios-arrow-forward" | name="ios-arrow-forward" | ||||
size={20} | size={20} | ||||
style={this.props.styles.forwardIcon} | style={this.props.styles.forwardIcon} | ||||
/> | /> | ||||
); | ); | ||||
fakeIcon = ( | fakeIcon = ( | ||||
<Icon | <Icon | ||||
name="ios-arrow-forward" | name="ios-arrow-forward" | ||||
size={20} | size={20} | ||||
style={this.props.styles.fakeIcon} | style={this.props.styles.fakeIcon} | ||||
/> | /> | ||||
); | ); | ||||
} | } | ||||
const title = isSearchEmpty ? 'New Message' : this.props.threadInfo.uiName; | |||||
const title = this.props.isSearchEmpty | |||||
? 'New Message' | |||||
: this.props.threadInfo.uiName; | |||||
return ( | return ( | ||||
<Button | <Button | ||||
onPress={this.onPress} | onPress={this.onPress} | ||||
style={this.props.styles.button} | style={this.props.styles.button} | ||||
androidBorderlessRipple={true} | androidBorderlessRipple={true} | ||||
disabled={areSettingsDisabled} | disabled={!this.props.areSettingsEnabled} | ||||
> | > | ||||
<View style={this.props.styles.container}> | <View style={this.props.styles.container}> | ||||
{fakeIcon} | {fakeIcon} | ||||
<HeaderTitle>{firstLine(title)}</HeaderTitle> | <HeaderTitle>{firstLine(title)}</HeaderTitle> | ||||
{icon} | {icon} | ||||
</View> | </View> | ||||
</Button> | </Button> | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |