index.js 1.74 KB
import React, { Component } from "react";
import {
  StyleSheet,
  WebView,
  View,
  Image,
  Dimensions,
  ScrollView,
  Text,
} from "react-native";
import { StackNavigator, TabNavigator } from "react-navigation";

export default class Discover extends Component {
  constructor(props) {
    super(props);
    this.state = {
      image: "",
    };
  }
  componentWillMount() {
    this.getImages();
  }
  getImages() {
    let that = this,
      id = this.state.id,
      model = this.state.model;
    return fetch(`https://devpay.brae.co/test/insurance/wallpaper`, {
      method: "POST",
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json"
      }
    })
      .then(resp => {
        console.log("大爷",resp);
        if (resp.status === 200) {
          return resp.json();
        } else {
          console.error("something went wrong!");
        }
      })
      .then(respJson => {
        if (respJson.enmsg != "ok") {
          alert(respJson.cnmsg);
        } else {
          that.setState({
            image: respJson.data.image
          });
          console.log("图片文章", respJson.data);
        }
      });
  }
  render() {
    const { image } = this.state;
    return (
      <View style={styles.container}>
        {/* <Text>图片首页</Text> */}
        <Image
          style={styles.image}
          source={{uri: image}}
          resizeMode="contain"
        >
          <Text>中央文案</Text>
        </Image>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "white"
  },
  image: {
    width: Dimensions.get("window").width,
    height: Dimensions.get("window").height,
    justifyContent: "center",
    alignItems: "center",
  }
});