Fix white screen of death and code/text preview in iOS (#1627)

This commit is contained in:
Elias Nahum 2018-04-26 12:23:17 -03:00 committed by GitHub
parent 0214480f61
commit 8807df1309
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 67 deletions

View file

@ -10,6 +10,7 @@ import {Client4} from 'mattermost-redux/client';
import UserStatus from 'app/components/user_status';
import ImageCacheManager from 'app/utils/image_cache_manager';
import {emptyFunction} from 'app/utils/general';
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
import placeholder from 'assets/images/profile.jpg';
@ -63,27 +64,25 @@ export default class ProfilePicture extends PureComponent {
}
componentWillUpdate(nextProps) {
if (
Boolean(nextProps.user) !== Boolean(this.props.user) ||
nextProps.user.id !== this.props.user.id ||
nextProps.user.last_picture_update !== this.props.user.last_picture_update
) {
this.setState({pictureUrl: null});
if (this.mounted) {
const url = this.state.pictureUrl;
const nextUrl = nextProps.user ? Client4.getProfilePictureUrl(nextProps.user.id, nextProps.user.last_picture_update) : null;
const nextUser = nextProps.user;
if (url !== nextUrl) {
this.setState({
pictureUrl: nextUrl,
});
if (this.mounted) {
this.setState({pictureUrl: null});
if (nextUrl) {
// empty function is so that promise unhandled is not triggered in dev mode
ImageCacheManager.cache('', nextUrl, this.setImageUrl).then(emptyFunction).catch(emptyFunction);
}
}
if (nextUser) {
ImageCacheManager.cache('', Client4.getProfilePictureUrl(nextUser.id, nextUser.last_picture_update), this.setImageURL);
if (nextProps.edit && nextProps.imageUri !== this.props.imageUri) {
this.setImageURL(nextProps.imageUri);
}
}
if (nextProps.edit && nextProps.imageUri !== this.props.imageUri) {
this.setImageURL(nextProps.imageUri);
}
}
componentWillUnmount() {

View file

@ -8,7 +8,6 @@ import {
ScrollView,
StyleSheet,
Text,
TextInput,
View,
} from 'react-native';
@ -50,27 +49,6 @@ export default class Code extends React.PureComponent {
lineNumbersStyle = style.lineNumbers;
}
let textComponent;
if (Platform.OS === 'ios') {
textComponent = (
<TextInput
editable={false}
multiline={true}
value={this.props.content}
style={[style.codeText]}
/>
);
} else {
textComponent = (
<Text
selectable={true}
style={style.codeText}
>
{this.props.content}
</Text>
);
}
return (
<ScrollView
style={style.scrollContainer}
@ -86,7 +64,12 @@ export default class Code extends React.PureComponent {
contentContainerStyle={style.code}
horizontal={true}
>
{textComponent}
<Text
selectable={true}
style={style.codeText}
>
{this.props.content}
</Text>
</ScrollView>
</ScrollView>
);
@ -131,9 +114,6 @@ const getStyleSheet = makeStyleSheetFromTheme((theme) => {
android: {
paddingVertical: 4,
},
ios: {
top: -4,
},
}),
},
codeText: {

View file

@ -8,7 +8,6 @@ import {
ScrollView,
StyleSheet,
Text,
TextInput,
View,
} from 'react-native';
@ -50,27 +49,6 @@ export default class TextPreview extends React.PureComponent {
lineNumbersStyle = style.lineNumbers;
}
let textComponent;
if (Platform.OS === 'ios') {
textComponent = (
<TextInput
editable={false}
multiline={true}
value={this.props.content}
style={[style.codeText]}
/>
);
} else {
textComponent = (
<Text
selectable={true}
style={style.codeText}
>
{this.props.content}
</Text>
);
}
return (
<ScrollView
style={style.scrollContainer}
@ -86,7 +64,12 @@ export default class TextPreview extends React.PureComponent {
horizontal={true}
contentContainerStyle={style.code}
>
{textComponent}
<Text
selectable={true}
style={style.codeText}
>
{this.props.content}
</Text>
</ScrollView>
</ScrollView>
);
@ -132,9 +115,6 @@ const getStyleSheet = makeStyleSheetFromTheme((theme) => {
android: {
paddingVertical: 4,
},
ios: {
top: -4,
},
}),
},
codeText: {