最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set Image to take the full size screen with header in react navigation? - Stack Overflow

programmeradmin1浏览0评论

I Have screen contain an image and I want to take the full-size screen with header?

I just use position: "absolute" but it's not working to wrap the header, and I can't use header: null because I want the back button to appear!

so how can I handle this?

what I get

what I want

Thanks in advance.

I Have screen contain an image and I want to take the full-size screen with header?

I just use position: "absolute" but it's not working to wrap the header, and I can't use header: null because I want the back button to appear!

so how can I handle this?

what I get

what I want

Thanks in advance.

Share Improve this question asked Sep 24, 2019 at 1:18 DevASDevAS 8272 gold badges18 silver badges44 bronze badges 3
  • How about position: fixed; top: 0; left: 0 ? – Yuan-Hao Chiang Commented Sep 24, 2019 at 1:50
  • 1 position in react-native can't take "Fixed" as the value just "relative | absolute" @Yuan-HaoChiang – DevAS Commented Sep 24, 2019 at 1:58
  • 1 Possible duplicate of What's the best way to add a full screen background image in React Native – Joy Biswas Commented Sep 24, 2019 at 2:13
Add a ment  | 

3 Answers 3

Reset to default 5

You can make header transparent for a specific screen by adding property headertransparent

Try this

 static navigationOptions = {
    headerTransparent: true,
  };

Complete Sample code

import React from "react";
import { View, Dimensions, Image } from "react-native";
import { createAppContainer, createStackNavigator } from "react-navigation";
import { Text } from "react-native";

const { width } = Dimensions.get("window");

class HomeScreen extends React.Component {
  static navigationOptions = {
    title: "Home"
  };

  render() {
    return (
      <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
        <Text
          style={{ padding: 20 }}
          onPress={() => this.props.navigation.navigate("Detail")}
        >
          Send To Detail
        </Text>
      </View>
    );
  }
}

class DetailScreen extends React.Component {
  static navigationOptions = {
    headerTransparent: true,
    headerTintColor: "#fff"
  };

  render() {
    return (
      <View style={{ flex: 1 }}>
        <Image
          style={{ width: width, height: 400 }}
          source={{
            uri:
              "https://media.gettyimages./photos/different-types-of-food-on-rustic-wooden-table-picture-id861188910?s=2048x2048",
            cache: "force-cache"
          }}
        />
      </View>
    );
  }
}

const AppNavigator = createStackNavigator({
  Home: {
    screen: HomeScreen
  },
  Detail: {
    screen: DetailScreen
  }
});

export default createAppContainer(AppNavigator);


App Demo

use this styling in header { position: 'absolute', zIndex: 100, top: 0, left: 0, right: 0, elevation: 0, shadowOpacity: 0, borderBottomWidth: 0 }

You need hide the header, if you are using react navigation, you can add the navigationOptions for add attributes for hide the header, like these lines.

static navigationOptions = {
    headerShown: false
  };
发布评论

评论列表(0)

  1. 暂无评论