React-native-fast-image: Add support for children.

Created on 20 Jun 2017  路  2Comments  路  Source: DylanVann/react-native-fast-image

Currently the component doesn't support children.

This is because FastImage supplies a android.widget.imageview and not a android.view.viewgroup.

For now absolute positioning is a workaround.

feature

Most helpful comment

My team built a short workaround (wrapper) for this.

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

export default class FastImageWeBurn extends Component {

  render() {
    const { children, ...otherProps } = this.props;

    const markup = Platform.OS === 'android' ? (
      <View>
        <FastImage {...otherProps} />
        <View>
          {children}
        </View>
      </View>
    ) : (
      <FastImage {...this.props} />
    );

    return markup;
  }
}

So while we now can use children on Android, it's still necessary to use absolute positioning within the FastImage Wrapper. E.g. we are using this to put transparent overlays on a FastImage. The overlay has the same size as the image and we position it absolute with top: -IMAGE_SIZE 馃憤

Hope this solution helps someone on here 鈽猴笍

All 2 comments

My team built a short workaround (wrapper) for this.

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

export default class FastImageWeBurn extends Component {

  render() {
    const { children, ...otherProps } = this.props;

    const markup = Platform.OS === 'android' ? (
      <View>
        <FastImage {...otherProps} />
        <View>
          {children}
        </View>
      </View>
    ) : (
      <FastImage {...this.props} />
    );

    return markup;
  }
}

So while we now can use children on Android, it's still necessary to use absolute positioning within the FastImage Wrapper. E.g. we are using this to put transparent overlays on a FastImage. The overlay has the same size as the image and we position it absolute with top: -IMAGE_SIZE 馃憤

Hope this solution helps someone on here 鈽猴笍

That's roughly how it's implemented now 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kmilodenisglez picture kmilodenisglez  路  3Comments

OmarBasem picture OmarBasem  路  3Comments

skleest picture skleest  路  3Comments

guihouchang picture guihouchang  路  4Comments

clay-morgan picture clay-morgan  路  3Comments