React-native-fast-image: Please allow contain children

Created on 3 Feb 2018  路  8Comments  路  Source: DylanVann/react-native-fast-image

Please allow contain children, Thank you!

Most helpful comment

We could add a ImageBackground Component. (https://facebook.github.io/react-native/docs/images.html#background-image-via-nesting)

In the meantime you can implement your own based on https://github.com/facebook/react-native/blob/8547b7e11163d545b7b99d4bdd063ef71129d62c/Libraries/Image/ImageBackground.js

Here is the component I use:

import React, { Component } from 'react'
import { View, StyleSheet } from 'react-native'
import FastImage from 'react-native-fast-image'

export default class ImageBackground extends Component {
  render() {
    const { children, style = {}, imageStyle, imageRef, ...props } = this.props

    return (
      <View style={style} ref={this._captureRef}>
        <FastImage
          {...props}
          style={[
            StyleSheet.absoluteFill,
            {
              width: style.width,
              height: style.height,
            },
            imageStyle,
          ]}
        />
        {children}
      </View>
    )
  }
}

All 8 comments

Children support was a feature deliberately removed in this commit to keep the API close to that of and potentially other reasons.

In other words, it's unlikely it'll be added again.

We could add a ImageBackground Component. (https://facebook.github.io/react-native/docs/images.html#background-image-via-nesting)

In the meantime you can implement your own based on https://github.com/facebook/react-native/blob/8547b7e11163d545b7b99d4bdd063ef71129d62c/Libraries/Image/ImageBackground.js

Here is the component I use:

import React, { Component } from 'react'
import { View, StyleSheet } from 'react-native'
import FastImage from 'react-native-fast-image'

export default class ImageBackground extends Component {
  render() {
    const { children, style = {}, imageStyle, imageRef, ...props } = this.props

    return (
      <View style={style} ref={this._captureRef}>
        <FastImage
          {...props}
          style={[
            StyleSheet.absoluteFill,
            {
              width: style.width,
              height: style.height,
            },
            imageStyle,
          ]}
        />
        {children}
      </View>
    )
  }
}

It supports children now. I was sort of flip flopping on how exactly to implement it for a bit.

Hello,

the problem is that "justifyContent" style property does not work for children.
I want to display children at the bottom of the image background by setting justifyContent : "flex-end", but it is not taken into account.
Do you know why ?

@appli-intramuros were you able to make it work? I am facing the exact same issue

@subhamagr I did not find any solution ...

@appli-intramuros, @subhamagr, justifyContent: 'flex-end' is working for me

@n1ru4l your method works like a charm, thank you good Sir!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

baba43 picture baba43  路  3Comments

Doko-Demo-Doa picture Doko-Demo-Doa  路  3Comments

guihouchang picture guihouchang  路  4Comments

banphlet picture banphlet  路  3Comments

kmilodenisglez picture kmilodenisglez  路  3Comments