Skip to content
Permalink
Browse files

fix tsc

  • Loading branch information...
xcarpentier committed May 13, 2019
1 parent 73e99bc commit a606cb61fc2d77d09092ca6c38d1892aabdc8177
Showing with 274 additions and 266 deletions.
  1. +56 −56 src/Day.tsx
  2. +53 −51 src/MessageImage.tsx
  3. +67 −64 src/Send.tsx
  4. +33 −31 src/SystemMessage.tsx
  5. +65 −64 src/Time.tsx
@@ -1,5 +1,5 @@
import PropTypes from 'prop-types'
import React from 'react'
import React, { PureComponent } from 'react'
import {
StyleSheet,
Text,
@@ -42,63 +42,63 @@ interface DayProps<TMessage extends IMessage = IMessage> {
inverted?: boolean
}

export default function Day(
{
dateFormat,
currentMessage,
previousMessage,
nextMessage,
containerStyle,
wrapperStyle,
textStyle,
inverted,
}: DayProps,
context: any,
) {
if (
currentMessage &&
!isSameDay(currentMessage, inverted ? previousMessage! : nextMessage!)
) {
return (
<View style={[styles.container, containerStyle]}>
<View style={wrapperStyle}>
<Text style={[styles.text, textStyle]}>
{moment(currentMessage.createdAt)
.locale(context.getLocale())
.format(dateFormat)
.toUpperCase()}
</Text>
</View>
</View>
)
export default class Day extends PureComponent<DayProps> {
static contextTypes = {
getLocale: PropTypes.func,
}
return null
}

Day.contextTypes = {
getLocale: PropTypes.func,
}
static defaultProps = {
currentMessage: {
// TODO: test if crash when createdAt === null
createdAt: null,
},
previousMessage: {},
nextMessage: {},
containerStyle: {},
wrapperStyle: {},
textStyle: {},
dateFormat: DATE_FORMAT,
}

Day.defaultProps = {
currentMessage: {
// TODO: test if crash when createdAt === null
createdAt: null,
},
previousMessage: {},
nextMessage: {},
containerStyle: {},
wrapperStyle: {},
textStyle: {},
dateFormat: DATE_FORMAT,
}
static propTypes = {
currentMessage: PropTypes.object,
previousMessage: PropTypes.object,
nextMessage: PropTypes.object,
inverted: PropTypes.bool,
containerStyle: ViewPropTypes.style,
wrapperStyle: ViewPropTypes.style,
textStyle: PropTypes.any,
dateFormat: PropTypes.string,
}
render() {
const {
dateFormat,
currentMessage,
previousMessage,
nextMessage,
containerStyle,
wrapperStyle,
textStyle,
inverted,
} = this.props

Day.propTypes = {
currentMessage: PropTypes.object,
previousMessage: PropTypes.object,
nextMessage: PropTypes.object,
inverted: PropTypes.bool,
containerStyle: ViewPropTypes.style,
wrapperStyle: ViewPropTypes.style,
textStyle: PropTypes.any,
dateFormat: PropTypes.string,
if (
currentMessage &&
!isSameDay(currentMessage, inverted ? previousMessage! : nextMessage!)
) {
return (
<View style={[styles.container, containerStyle]}>
<View style={wrapperStyle}>
<Text style={[styles.text, textStyle]}>
{moment(currentMessage.createdAt)
.locale(this.context.getLocale())
.format(dateFormat)
.toUpperCase()}
</Text>
</View>
</View>
)
}
return null
}
}
@@ -1,5 +1,5 @@
import PropTypes from 'prop-types'
import React from 'react'
import React, { Component } from 'react'
import {
Image,
StyleSheet,
@@ -13,42 +13,6 @@ import {
import Lightbox from 'react-native-lightbox'
import { IMessage } from './types'

interface MessageImageProps<TMessage extends IMessage = IMessage> {
currentMessage?: TMessage
containerStyle?: ViewStyle
imageStyle?: ImageStyle
imageProps?: Partial<ImageProps>
lightboxProps?: object
}

export default function MessageImage({
containerStyle,
lightboxProps,
imageProps,
imageStyle,
currentMessage,
}: MessageImageProps) {
if (!!currentMessage) {
return (
<View style={[styles.container, containerStyle]}>
<Lightbox
activeProps={{
style: styles.imageActive,
}}
{...lightboxProps}
>
<Image
{...imageProps}
style={[styles.image, imageStyle]}
source={{ uri: currentMessage.image }}
/>
</Lightbox>
</View>
)
}
return null
}

const styles = StyleSheet.create({
container: {},
image: {
@@ -64,20 +28,58 @@ const styles = StyleSheet.create({
},
})

MessageImage.defaultProps = {
currentMessage: {
image: null,
},
containerStyle: {},
imageStyle: {},
imageProps: {},
lightboxProps: {},
interface MessageImageProps<TMessage extends IMessage = IMessage> {
currentMessage?: TMessage
containerStyle?: ViewStyle
imageStyle?: ImageStyle
imageProps?: Partial<ImageProps>
lightboxProps?: object
}

MessageImage.propTypes = {
currentMessage: PropTypes.object,
containerStyle: ViewPropTypes.style,
imageStyle: PropTypes.object,
imageProps: PropTypes.object,
lightboxProps: PropTypes.object,
export default class MessageImage extends Component<MessageImageProps> {
static defaultProps = {
currentMessage: {
image: null,
},
containerStyle: {},
imageStyle: {},
imageProps: {},
lightboxProps: {},
}

static propTypes = {
currentMessage: PropTypes.object,
containerStyle: ViewPropTypes.style,
imageStyle: PropTypes.object,
imageProps: PropTypes.object,
lightboxProps: PropTypes.object,
}
render() {
const {
containerStyle,
lightboxProps,
imageProps,
imageStyle,
currentMessage,
} = this.props
if (!!currentMessage) {
return (
<View style={[styles.container, containerStyle]}>
<Lightbox
activeProps={{
style: styles.imageActive,
}}
{...lightboxProps}
>
<Image
{...imageProps}
style={[styles.image, imageStyle]}
source={{ uri: currentMessage.image }}
/>
</Lightbox>
</View>
)
}
return null
}
}
@@ -1,5 +1,5 @@
import PropTypes from 'prop-types'
import React from 'react'
import React, { Component } from 'react'
import {
StyleSheet,
Text,
@@ -11,51 +11,6 @@ import {
} from 'react-native'
import Color from './Color'

interface SendProps {
text?: string
label?: string
containerStyle?: ViewStyle
textStyle?: TextStyle
children?: React.ReactNode
alwaysShowSend?: boolean
disabled?: boolean
onSend?({ text }: { text: string }, b: boolean): void
}

export default function Send({
text,
containerStyle,
onSend,
children,
textStyle,
label,
alwaysShowSend,
disabled,
}: SendProps) {
if (alwaysShowSend || (text && text.trim().length > 0)) {
return (
<TouchableOpacity
testID='send'
accessible
accessibilityLabel='send'
style={[styles.container, containerStyle]}
onPress={() => {
if (text && onSend) {
onSend({ text: text.trim() }, true)
}
}}
accessibilityTraits='button'
disabled={disabled}
>
<View>
{children || <Text style={[styles.text, textStyle]}>{label}</Text>}
</View>
</TouchableOpacity>
)
}
return <View />
}

const styles = StyleSheet.create({
container: {
height: 44,
@@ -72,24 +27,72 @@ const styles = StyleSheet.create({
},
})

Send.defaultProps = {
text: '',
onSend: () => {},
label: 'Send',
containerStyle: {},
textStyle: {},
children: null,
alwaysShowSend: false,
disabled: false,
interface SendProps {
text?: string
label?: string
containerStyle?: ViewStyle
textStyle?: TextStyle
children?: React.ReactNode
alwaysShowSend?: boolean
disabled?: boolean
onSend?({ text }: { text: string }, b: boolean): void
}

Send.propTypes = {
text: PropTypes.string,
onSend: PropTypes.func,
label: PropTypes.string,
containerStyle: ViewPropTypes.style,
textStyle: PropTypes.any,
children: PropTypes.element,
alwaysShowSend: PropTypes.bool,
disabled: PropTypes.bool,
export default class Send extends Component<SendProps> {
static defaultProps = {
text: '',
onSend: () => {},
label: 'Send',
containerStyle: {},
textStyle: {},
children: null,
alwaysShowSend: false,
disabled: false,
}

static propTypes = {
text: PropTypes.string,
onSend: PropTypes.func,
label: PropTypes.string,
containerStyle: ViewPropTypes.style,
textStyle: PropTypes.any,
children: PropTypes.element,
alwaysShowSend: PropTypes.bool,
disabled: PropTypes.bool,
}

render() {
const {
text,
containerStyle,
onSend,
children,
textStyle,
label,
alwaysShowSend,
disabled,
} = this.props
if (alwaysShowSend || (text && text.trim().length > 0)) {
return (
<TouchableOpacity
testID='send'
accessible
accessibilityLabel='send'
style={[styles.container, containerStyle]}
onPress={() => {
if (text && onSend) {
onSend({ text: text.trim() }, true)
}
}}
accessibilityTraits='button'
disabled={disabled}
>
<View>
{children || <Text style={[styles.text, textStyle]}>{label}</Text>}
</View>
</TouchableOpacity>
)
}
return <View />
}
}
Oops, something went wrong.

0 comments on commit a606cb6

Please sign in to comment.
You can’t perform that action at this time.