import React, { Component } from 'react' import {View, ScrollView, StyleSheet, Linking, Button, TouchableOpacity, Alert, Platform, Modal, ImageBackground} from 'react-native'; import Image from 'react-native-fast-image' import { WebView } from 'react-native-webview'; import { Body, Badge, List, ListItem, Right, Title } from 'native-base' import Icon from '../../components/Icon' import Text from '../../components/Text'; import LinearGradient from 'react-native-linear-gradient'; import { BackgroundImage } from '../../components/BackgroundImage' import { getNewsDetail } from '../../api/UserApi'; import IndicatorLoading from '../../components/IndicatorLoading'; import { t } from '../../utils/i18n' import parseDateLocale from '../../utils/parseDateLocale'; import ImageView from 'react-native-image-view'; import {NavigationActions} from "react-navigation"; import Config from 'src/utils/Config' import Carousel from "../room/RoomDetail"; import {sliderWidth} from "../../styles/SliderEntry.style"; var uri = null; const injectScript = ` (function () { window.onclick = function(e) { e.preventDefault(); window.postMessage(e.target.href); e.stopPropagation() } }()); `; export default class NewsDetailScreen extends Component { constructor(props) { super(props) this.state = { isLoading: true, isImageViewVisible: false, content:'', news_id: this.props.navigation.getParam('news_id', 'NO ITEM'), news_detail:{} } } componentDidMount(){ this.getNewsData() }; /*componentWillUnmount() { if(this.props && this.props.navigation && this.props.navigation.state && this.props.navigation.state.params && this.props.navigation.state.params.getNotification){ this.props.navigation.state.params.getNotification() } }*/ getNewsData(){ this.setState({ isLoading: true }) getNewsDetail(this.state.news_id) .then(res => { if(res.ok){ if(res.data.data){ this.setState({ isLoading: false, news_detail: res.data.data }) }else { console.log('ถูกยกเลิกเผยแพร่ข่าว') Alert.alert('','ถูกยกเลิกเผยแพร่ข่าว', [{ text: t('ok'), onPress: () => { console.log('press') this.setState({ isLoading: false, news_detail: {} }) } }]) } }else{ Alert.alert('','ถูกยกเลิกเผยแพร่ข่าว', [{ text: t('ok'), onPress: () => { this.setState({ isLoading: false, news_detail: {} }) } }]) // alert('ถูกยกเลิกเผยแพร่ข่าว') // this.context.router.goBack() } }) } render() { let source_webview = {}; if(Platform.OS === 'android'){ source_webview = { baseUrl: '', uri: `${Config.WEB_BASE_URL_PROD}/news_detail/${this.state.news_id}` } }else { source_webview = { baseUrl: '', html: `${this.state.news_detail && this.state.news_detail.style ? this.state.news_detail.style : ''}
${this.state.news_detail && this.state.news_detail.content ? this.state.news_detail.content : ""}
` } } return ( { Platform.OS === 'android' && {this.setState({isImageViewVisible: false})}} /> } {this.setState({isImageViewVisible: true})}}> {this.state.news_detail != null && this.state.news_detail.title} { this.state.news_detail && {parseDateLocale(this.state.news_detail.date)} } {this.state.news_detail && this.state.news_detail.is_new == true ? {this.state.news_detail.type === 'promotion' ? t('latest_promotion') : t('latest_news')} : null} {t('detail')} ${this.state.news_detail && this.state.news_detail.content ? this.state.news_detail.content : ""} ` }} source={source_webview} ref={(ref) => { this.webview = ref; }} javaScriptEnabled={true} domStorageEnabled={true} onMessage={(event) => { if(event.nativeEvent.data){ let data = JSON.parse(event.nativeEvent.data); if(data.video_id){ Linking.openURL(`https://youtube.com/embed/${data.video_id}`); } } }} /*onNavigationStateChange={(event) => { console.log('onNavigationStateChange >>>>>> ',event); if (event.url.startsWith("http")) { this.webview.stopLoading(); this.webview.goBack(); Linking.openURL(event.url); } }}*/ /> { Platform.OS === 'ios' && { Alert.alert('Modal has been closed.'); }}> {this.setState({isImageViewVisible:false})}} > } ) } } const styles = StyleSheet.create({ imgBg: { width: '100%', height: 200, paddingTop: 80 }, textNews: { backgroundColor: '#0D8890', width: 60, color: '#FFFFFF', borderRadius: 5, textAlign: 'center', fontSize: 12 }, backgroundImage: { flex: 1, width: null, height: null, resizeMode: 'cover' } })