Commit c4940e3f authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

nambahin try cath untuk menangkap error di hp pak benny

parent 0c07d48d
This diff is collapsed.
import React from 'react';
import { View, Text, StyleSheet, Dimensions } from 'react-native';
import { View, Text, StyleSheet, Dimensions, Alert } from 'react-native';
import { Image } from 'react-native-elements';
import Axios from 'axios';
import { TouchableOpacity, ScrollView } from 'react-native-gesture-handler';
......@@ -20,53 +20,68 @@ export default class NewsDetail extends React.Component {
}
componentDidMount() {
const screenWidth = Math.round(Dimensions.get('window').width);
const statusBarHeight = getStatusBarHeight();
this.setState({
image_height: screenWidth,
statusbar_height: statusBarHeight
})
this.get_news_detail(this.props.route.params.slug)
try {
const screenWidth = Math.round(Dimensions.get('window').width);
const statusBarHeight = getStatusBarHeight();
this.setState({
image_height: screenWidth,
statusbar_height: statusBarHeight
})
this.get_news_detail(this.props.route.params.slug)
} catch (error) {
Alert.alert('Error', + error)
}
}
get_news_detail(slug) {
Axios.get('https://excelsocrm.ravintoladev.com/cms/v2/detail/' + slug).then(res => {
const detail = res.data;
this.setState({
title: detail.title,
subtitle: detail.subtitle,
image: detail.content_image,
content: detail.content,
})
})
try {
Axios.get('https://excelsocrm.ravintoladev.com/cms/v2/detail/' + slug).then(res => {
const detail = res.data;
this.setState({
title: detail.title,
subtitle: detail.subtitle,
image: detail.content_image,
content: detail.content,
})
})
} catch (error) {
Alert.alert('Error:'+ error)
}
}
render() {
// console.log(this.state.content)
return (
<View style={styles.container}>
<MyStatusBar />
<ScrollView style={styles.body}>
<View style={styles.image_container(this.state.image_height)}>
<Image style={styles.image(this.state.image_height)} source={this.state.image ? { uri: this.state.image } : null} />
</View>
<View style={styles.content}>
<Text style={styles.title}>{this.state.title}</Text>
<View style={{ backgroundColor: '#adadad', height: 1.5, flex: 1, marginBottom: 5 }} />
<HTML html={this.state.content} tagsStyles={{
p: { fontSize: 12, color: '#838383', fontFamily: 'Gotham-Light' },
blockquote: { backgroundColor: "#f1f1f1", padding: 12, paddingBottom: 0, marginTop: 0 },
li: { fontSize: 12, color: '#838383', fontFamily: 'Gotham-Light', marginBottom : 0 },
ul: { fontSize: 12, color: '#838383', fontFamily: 'Gotham-Light', marginVertical: 5, marginBottom : -10 },
}}
ignoredTags={['br']}
ignoredStyles={['font-family','&nbsp;', '&amp;']} />
</View>
</ScrollView>
</View>
)
try {
return (
<View style={styles.container}>
<MyStatusBar />
<ScrollView style={styles.body}>
<View style={styles.image_container(this.state.image_height)}>
<Image style={styles.image(this.state.image_height)} source={this.state.image ? { uri: this.state.image } : null} />
</View>
<View style={styles.content}>
<Text style={styles.title}>{this.state.title}</Text>
<View style={{ backgroundColor: '#adadad', height: 1.5, flex: 1, marginBottom: 5 }} />
<HTML html={this.state.content} tagsStyles={{
p: { fontSize: 12, color: '#838383', fontFamily: 'Gotham-Light' },
blockquote: { backgroundColor: "#f1f1f1", padding: 12, paddingBottom: 0, marginTop: 0 },
li: { fontSize: 12, color: '#838383', fontFamily: 'Gotham-Light', marginBottom : 0 },
ul: { fontSize: 12, color: '#838383', fontFamily: 'Gotham-Light', marginVertical: 5, marginBottom : -10 },
}}
ignoredTags={['br']}
ignoredStyles={['font-family','&nbsp;', '&amp;']} />
</View>
</ScrollView>
</View>
)
} catch (error) {
Alert.alert('Error' + error)
}
}
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment