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

javascript - Prevent white edges during orientation change - Stack Overflow

programmeradmin9浏览0评论

I reproduce this issue with the most minimal React-Native app:

render() {
  return View({style: {
    flex: 1,
    backgroundColor: 'black'
  }})
}

When I rotate my phone, one side of the screen has a white section during the orientation transition. How can I color that area the same as the rest of the background?

I reproduce this issue with the most minimal React-Native app:

render() {
  return View({style: {
    flex: 1,
    backgroundColor: 'black'
  }})
}

When I rotate my phone, one side of the screen has a white section during the orientation transition. How can I color that area the same as the rest of the background?

Share Improve this question edited Apr 9, 2016 at 1:27 m59 asked Apr 9, 2016 at 1:20 m59m59 43.8k14 gold badges121 silver badges139 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

In the RootView of your app, the default background color is white. You can change this to another color by using the following steps:

In this example we'll set the background color to black on iOS.

Open AppDelegate.m located in PROJECT_DIR/ios/Appname/ for editing.

Locate snippet that looks similar to the following:

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                  moduleName:@"Appname"
                                           initialProperties:nil
                                               launchOptions:launchOptions];

Add the following line of code immediately after the previous snippet:

rootView.backgroundColor = [UIColor blackColor];

The resulting code block should look like the following:

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                moduleName:@"Appname"
                                         initialProperties:nil
                                             launchOptions:launchOptions];

rootView.backgroundColor = [UIColor blackColor];

BAM! RootView background color is set on iOS!

This information and more is available from this blog post: Changing the React Native RootView Background Color (iOS and Android) by Jay Garcia. (I believe the Android information in this post may be out of date, which is why I didn't include steps for Android).

Hope this helps!

I created a library, it allows you to do it from the level of JavaScript, and also allows you to do dynamic changes.

https://github./johniak/react-native-root-view-background

import { setRootViewBackgroundColor } from 'react-native-root-view-background';

export default class Main extends Component {
    ponentDidMount(){
        setRootViewBackgroundColor('#ccc');
    }
}

I am not sure what you are referring to here. But what ever is containing that view needs to have its background set also perhaps?

发布评论

评论列表(0)

  1. 暂无评论