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.

Turn off all edges?

See original GitHub issue

I would like to be able to pass an empty array to the edges prop of SafeAreaView when I don’t want any safe area edges. The use case is a reusable component that on some screens I want it to take into account Safe Area, and other screens already take Safe Area into account and I don’t want double padding. So I’d like to pass a prop to my reusable component that can be used like so:

const MyComponent = ({ needsSafeArea }) => {
  const edges = [];
  if (needsSafeArea) {
    edges.push('top');
  }

  return (<SafeAreaView edges={edges}>
    {/* My cool component */}    
  </SafeAreaView>);
};

This code currently results in all edges being activated when needsSafeArea is false. If there’s a better way to handle my use case then please let me know.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:6

github_iconTop GitHub Comments

8reactions
duggstercommented, Jul 15, 2021

Yes this is a workaround, but not great because you either have to duplicate the code inside or create another layer of abstraction by factoring out the common code into yet another component. It would be much more readable and maintainable to just keep the SafeAreaView structure in place and control the behavior by props.

An empty edges array seemed intuitive to indicate no edges at first (before I re-read the docs), but probably it would be less disruptive to existing code if an optional flag was added called something like ‘disabled’.

4reactions
CptFabulousocommented, Aug 13, 2021

I’ve also come to few use cases where I’d use that passing edges={[]} turns off all edges. It’s surprising to me it doesn’t, because the code clearly says what I want and that is to use no edges. If it would work like that and you would have opposite condition like “if something is true, I want only top edge, otherwise use default edges” you could still do that by edges={condition? ['top'] : undefined}, so to me it seems like win-win.

Anyway, best workaround I found is to use useSafeAreaInsets

import React from 'react';
import { View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

const MyComponent = ({ needsSafeArea }) => {
 const { top } = useSafeAreaInsets();
 return (
   <View style={{paddingTop: needsSafeArea? top : 0}}>
     {/* My cool component */}    
   </View>
 );
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to disable Edge - Microsoft Community
Hold down the Ctrl and Alt keys and tap the delete key, then click on Task Manager. If it says "More details" at...
Read more >
How to Disable Microsoft Edge as Your Default Browser in 2022
Launch Microsoft Edge; Click the three dots in the top-right corner; Select “settings” ; Select “system” in the menu on the left side...
Read more >
How to Disable Microsoft Edge on Windows 10 | SoftwareKeep
Method 2. Uninstall Microsoft Edge · Open the Settings app by clicking on the gear icon in the Start menu. · Click on...
Read more >
How to Stop Microsoft Edge from Running in the Background ...
To stop it from running in the background first launch Microsoft Edge. Then click the Options button (three dots) and choose Settings from...
Read more >
3 Easy Ways to Remove Edge Notifications - wikiHow
1. Open Settings. You can press the Windows key and I to open settings, or you can search for it in the search...
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