12

The documentation provided an example for StyleSheet.absoluteFillObject() whose behavior is also same while using with StyleSheet.absoluteFill():

const styles = StyleSheet.create({
  wrapper: {
    ...StyleSheet.absoluteFillObject,
    top: 10,
    backgroundColor: 'transparent',
  },
});

What is the difference between StyleSheet.absoluteFill() and StyleSheet.absoluteFillObject()? A little example will be more appreciated. Thanks !!!

Purple Bytes
  • 489
  • 2
  • 6
  • 16

5 Answers5

14

absoluteFill is an easy way to set a view to be full screen and absolute positioned. It’s a short cut for:

{
 position: 'absolute',
 top: 0,
 left: 0,
 bottom: 0,
 right: 0

}

Use it to extend your other styles like this:

const styles = StyleSheet.create({
  container: {
   backgroundColor: 'red'
   }
});
<View style={[StyleSheet.absoluteFill, styles.container]} />

absoluteFillObject Say you want to absolute position your view, but bump it down 20px to offset for the status bar (for example). You can spread StyleSheet.absoluteFillObject into your style and then override one of it’s values.

const styles = StyleSheet.create({
  container: {
    ...StyleSheet.absoluteFillObject,
   top: 20,
    backgroundColor: 'red'
  }
});
<View style={styles.container} />
Charles Owen
  • 1,569
  • 10
  • 18
  • 8
    The thing you mention in the answer for `StyleSheet.absoluteFillObject` can also be done with the `StyleSheet.absoluteFill`, so, what can be the difference? – Purple Bytes Dec 08 '18 at 05:34
9

There is no difference between those two. You can see this in StyleSheet.js enter image description here

Gintama
  • 1,073
  • 19
  • 29
  • 2
    Yes, "Use the Source, Luke"! Here's the reference to check what is the situation in the latest version: https://github.com/facebook/react-native/blob/master/Libraries/StyleSheet/StyleSheet.js#L266 – iqqmuT Jul 06 '20 at 12:46
2

As of version 0.62, no difference at all according to the official document

In case you are using EXPO Snack like I do, the absoluteFill preview on web seems buggy at this time. On a real device, it should be fine.

Bobby Chang Liu
  • 101
  • 1
  • 4
0

Currently, there is no difference between using absoluteFill vs. absoluteFillObject.

Penny Liu
  • 7,720
  • 5
  • 40
  • 66
agnes_st
  • 27
  • 2
0

I've tried to print the value of absoluteFill and absoluteFillObject.
They're no difference. They're the same value.

[LOG] absoluteFill: {"bottom": 0, "left": 0, "position": "absolute", "right": 0, "top": 0}
[LOG] absoluteFillObject: {"bottom": 0, "left": 0, "position": "absolute", "right": 0, "top": 0}
Illuminator
  • 446
  • 6
  • 12