question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does SafeAreaView support android?

See original GitHub issue

I am testing SafeAreaView but this seems not to work on Android.

My app has a minimalistic design and I have hidden the status bar… So, that is why I wrapped most of my components inside your component… The problem is that I have had to write an extra padding for Android like this:

import React from “react”; import { StyleSheet, Platform, StatusBar } from “react-native”; import { SafeAreaView } from “react-native-safe-area-context”;

export default function (props) {
  return (
    <SafeAreaView style={styles.AndroidSafeArea} {...props}>
      {props.children}
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  AndroidSafeArea: {
    paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0,
  },
});

Something that doesn’t seems really elegant.

Will this feature be implemented in a future so that I don’t have to use this custom component?

Thank you.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
kuasha420commented, Nov 13, 2020

It works on android for sure. Are you sure you haven’t imported SafeAreaView from ‘react-native’ ?

0reactions
jason-rb2commented, Jul 22, 2021

@nickelbob i solved this by follows, you can have a try:

import React from 'react';
import {
  SafeAreaView,
  NativeSafeAreaViewProps,
  useSafeAreaInsets,
  EdgeInsets,
  Edge,
} from 'react-native-safe-area-context';
import styled, { css } from 'styled-components';

const SafeAreaViewStyled = styled(SafeAreaView)<{
  insets: EdgeInsets;
  edges: readonly Edge[];
  mode: 'padding' | 'margin';
}>`
  flex: 1;
  ${(p) =>
    p.edges.map(
      (direction) => css`
        ${p.mode}-${direction}: ${p.insets[direction]}px;
      `,
    )}
  background: #fff;
`;

export const CustomSafeAreaView: React.FC<NativeSafeAreaViewProps> = ({
  children,
  edges = ['top', 'right', 'bottom', 'left'],
  ...restProps
}) => {
  const insets = useSafeAreaInsets();

  return (
    <SafeAreaViewStyled edges={edges} insets={insets} mode="padding" {...restProps}>
      {children}
    </SafeAreaViewStyled>
  );
};


Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use SafeAreaView for Android notch devices?
The SafeAreaView is a solution for the iPhone X but for Android, it seems there is no solution. How to solve this kind...
Read more >
(React native) How to use SafeAreaView for Android notch ...
Android : (React native) How to use SafeAreaView for Android notch devices?
Read more >
SafeAreaView for Android devices | Voters - Expo
Hi, SafeAreaView works great for iOS, but there is still many android devices that we are not giving a great support like moto...
Read more >
SafeAreaView - React Native
The purpose of SafeAreaView is to render content within the safe area boundaries of a device. It is currently only applicable to iOS...
Read more >
How to Use Safe Area Context in React Native Apps to Avoid ...
The SafeAreaView acts like a regular View component from React Native and includes additional padding to position the content below the notch or ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found