Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SafeAreaView doesn't work on iOS 10 and below #17638

Closed
greenraze opened this issue Jan 17, 2018 · 20 comments
Closed

SafeAreaView doesn't work on iOS 10 and below #17638

greenraze opened this issue Jan 17, 2018 · 20 comments
Labels
Platform: iOS iOS applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@greenraze
Copy link

greenraze commented Jan 17, 2018

Is this a bug report?

don't know

Environment

Environment:
OS: macOS Sierra 10.12.6
Node: 8.4.0
Xcode: 9.2

react-native: 0.48.1 => 0.48.1
react: 16.0.0-alpha.12 => 16.0.0-alpha.12

Target Platform: iOS 10 and greater

Steps to Reproduce

in my index.ios.js


`render() {
    StatusBar.setBarStyle('light-content', true);
    StatusBar.setTranslucent(true)
    StatusBar.setHidden(true)
    return (
      <SafeAreaView style={{ flex:1,backgroundColor:BACKGROUND,}}>
        <View style={{flex:1}}>
          <StatusBar hidden={true} />
          <Provider  store={store}>
            <RouterComponent />
          </Provider>
        </View>
      </SafeAreaView>

    );
  } 
)`

My React Native app on iOS 10 starts from under the status bar but in iOS 11 the app starts from below the status bar. I want to start the app from 0x 0y off screen for all versions of iOS and the nav bar under the status bar. In Android there is a function called setTranslucent() but on iOS I didn't find a function which supports this. In my index.ios.js
@redmar @mojodna @aroth

@igorpan
Copy link

igorpan commented Jan 20, 2018

Have the exact same issue with SafeAreaView. Definitely smells like a bug.

Same code running in two simulators side by side. Happens on actual devices too:
image

Code:

class ListPageHeader extends React.Component {
  static propTypes = {
    title: PropTypes.string.isRequired,
    actions: PropTypes.arrayOf(PropTypes.object),
    onSearchChange: PropTypes.func,
  };

  static defaultProps = {
    actions: []
  };

  render() {
    const { title, actions, onSearchChange } = this.props;

    return (
      <SafeAreaView style={styles.wrapper}>
        <View style={styles.padding}>
          <PageTitle text={title} />
          <View style={styles.actions}>
            {actions.map((action, i) => <Action key={i} action={action} />)}
          </View>
        </View>
        <SearchBar onSearchChange={onSearchChange} containerStyle={styles.searchBar} />
      </SafeAreaView>
    );
  }
}

const styles = StyleSheet.create({
  wrapper: {
    backgroundColor: '#ffffff',
  },
  searchBar: {
    paddingTop: 9,
    paddingBottom: 30,
  },
  padding: {
    paddingLeft: 15,
    paddingRight: 15,
    paddingTop: 15,
    flexDirection: 'row',
    alignItems: 'flex-end',
    justifyContent: 'space-between',
  },
  actions: {
    flexDirection: 'row',
  }
});

The workaround we currently use is to add padding to our heading component if iOS version is under 11:

const majorVersionIOS = parseInt(Platform.Version, 10);
const paddingTop = majorVersionIOS < 11? 35 : 15;

@thame
Copy link

thame commented Feb 16, 2018

I noticed the same issue which appears to be dependent on the iOS version. SafeAreaView does not seem to provide any space for the StatusBar on iOS 10 (I tested this on iOS 10.3), but works perfectly on iOS 11.

My fix was to use this package instead: react-native-safe-area-view

@vovkasm
Copy link
Contributor

vovkasm commented Feb 18, 2018

It is because SafeAreaView in RN (at least in 0.53) is simple converts UIView.safeAreaInsets property to RCTView paddings. But safeAreaInsets was introduced only in iOS 11. So on iOS 10 it's currently noop.

Indeed iOS provides another (now deprecated and bad designed imho) way to get "safe area" on pre iPhone X devices: UIViewController.topLayoutGide. This method has many problems to be integrated into RN properly mainly because it operated on View Controllers level, but RN operates on UIView level, e.g. standalone RN application has one naked UIViewController that contains only default logic... I think backward compatibility for SafeAreaView can be implemented, may be someone will fork RN SafeAreaView, improve and release to npm as independent package.

PS. mentioned react-native-safe-area-view - is totally incorrect, it simple hardcode all metrics... it will be always buggy and your app will be broken on every new iOS release :-)

@react-native-bot

This comment has been minimized.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon. labels Feb 24, 2018
@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 24, 2018
@douglasjunior
Copy link

douglasjunior commented Feb 25, 2018

Still not working with React Native 0.53.

For me it works with react-native-safe-area-view.

@hramos hramos reopened this Mar 1, 2018
@facebook facebook deleted a comment from salmanwaheed Mar 5, 2018
@hramos
Copy link
Contributor

hramos commented Mar 5, 2018

Looks like @vovkasm clearly describe why this happens on iOS 10: #17638 (comment). Closing as that seems to provide a reasonable workaround.

@grabbou
Copy link
Contributor

grabbou commented Mar 22, 2018

@hramos we should provide a warning when SafeAreaView is used on iOS 10 and below. Right now, it silently fails to work - for people (like me) relying on status bar padding this is providing hard to debug glitches.

CC: @satya164

@grabbou grabbou reopened this Mar 22, 2018
@grabbou grabbou changed the title draw the app under the status bar in react native SafeAreaView doesn't work on iOS 10 and below Mar 22, 2018
@satya164
Copy link
Contributor

@grabbou is there a constant exposed for statusbar height on iOS? if it is, then we could use it on older versions of iOS for SafeAreaView.

@vovkasm
Copy link
Contributor

vovkasm commented Mar 22, 2018

Status bar height is not a constant on iOS. It can change dynamically, e.g. while incoming call.

But ideally SafeAreaView can measure view controller's layout gides on older versions of ios.

@satya164
Copy link
Contributor

@vovkasm yeah, but SafeAreaView can automatically do that since it's a native component

@vovkasm
Copy link
Contributor

vovkasm commented Mar 22, 2018

Right. And I mention that already in #17638 (comment)

@vovkasm
Copy link
Contributor

vovkasm commented Mar 24, 2018

Just create PR #18534, can anyone test it in real application?

@grabbou
Copy link
Contributor

grabbou commented Mar 24, 2018

Let's carry on the review process in there. I'll try to give it a shot since I am working on the library that uses it heavily right now.

Thanks for submitting pull request :)

@stale
Copy link

stale bot commented Jun 22, 2018

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 22, 2018
@vovkasm
Copy link
Contributor

vovkasm commented Jun 22, 2018

All right bots... Issue is still actual. But no one is concerned, so we have our own fork of RN with proper fix.

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 22, 2018
@randomco
Copy link

Tested safeareaview on RN 0.55, it does not work on or below iOS 10. Application goes behind the status bar.

@vovkasm
Copy link
Contributor

vovkasm commented Jul 19, 2018

@randomco PR #18534 still not merged, so this bug exists also in 0.56 and in master. You can fork RN and apply this patch. I'am currently slowly try to implement independent module with this functional, that also will fix other gotchas with RN implementation.

@blac3777
Copy link

While this is being taken care of, could SafeAreaView also be made to avoid content from going under the statusbar on android? I don't like having to hard-code margin height, it seems sketchy and destined to result in future bugs. Also, SafeAreaView should be able to avoid statusbar on ios and android w/o separate implementations.

@ronilitman
Copy link

Same issue. The solution that I found is to use this library from the time being, same implementation:
https://github.com/react-community/react-native-safe-area-view

t-nanava pushed a commit to microsoft/react-native-macos that referenced this issue Jun 17, 2019
Summary:
Currently `SafeAreaView` works only on iOS 11, because implemented in terms of native safeArea API, that not exists in older iOS versions. But this make it hard to use the component in real applications, because content will be under top bars on older versions of iOS and no reliable way to workaround this in js. More motivation in facebook#17638

This changeset emulate safe area in terms of `UIViewController` layout guides API if safeArea not available.

Fixes facebook#17638, facebook#18255

I run RNTester with these simulators: iPhone6 (9.3), iPhone6 (10.0), iPhone6 (11.2), iPhoneX (11.2)
- Start RNTester application
- Look on top header, it should not overlap status bar
- Go to the `<SafeAreaView>` example, open modal
- Modal area should not overlap status bar

<img src="http://vovkasm.skitch.vovkasm.org/iPhone6_10_20662C5B.png" width="40%"> <img src="http://vovkasm.skitch.vovkasm.org/iPhone6_11_20662CC8.png" width="40%">

<img src="http://vovkasm.skitch.vovkasm.org/iPhone6_10_pr_20662DE6.png" width="40%"> <img src="http://vovkasm.skitch.vovkasm.org/iPhone6_11_pr_20662DA8.png" width="40%">

[IOS] [BUGFIX] [SafeAreaView] - Make SafeAreaView to work on iOS < 11
Pull Request resolved: facebook#18534

Reviewed By: PeteTheHeat, shergin

Differential Revision: D9166052

Pulled By: hramos

fbshipit-source-id: c086e1ae4af13110a7453b770ca75b6e0d5321ea
@nikola-kolosek
Copy link

Quick workaround:

const WorkaroundView = props => {
  if (Platform.OS === 'ios' && Platform.Version < 11)
    return <View {...props} style={[props.style, { paddingTop: 15 }]} /> // Add padding to avoid rendering behind StatusBar
  else return <SafeAreaView {...props} />
}

Then use <WorkaroundView> as a component

@facebook facebook locked as resolved and limited conversation to collaborators Aug 23, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Aug 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: iOS iOS applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests