PHP 7.4.33
Preview: ImageBackground.js Size: 3.14 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/react-native/Libraries/Image/ImageBackground.js
/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow strict-local
 * @format
 */

import type {HostInstance} from '../Renderer/shims/ReactNativeTypes';
import type {ImageBackgroundProps} from './ImageProps';

import View from '../Components/View/View';
import flattenStyle from '../StyleSheet/flattenStyle';
import StyleSheet from '../StyleSheet/StyleSheet';
import Image from './Image';
import * as React from 'react';

/**
 * Very simple drop-in replacement for <Image> which supports nesting views.
 *
 * ```ReactNativeWebPlayer
 * import React, { Component } from 'react';
 * import { AppRegistry, View, ImageBackground, Text } from 'react-native';
 *
 * class DisplayAnImageBackground extends Component {
 *   render() {
 *     return (
 *       <ImageBackground
 *         style={{width: 50, height: 50}}
 *         source={{uri: 'https://reactnative.dev/img/opengraph.png'}}
 *       >
 *         <Text>React</Text>
 *       </ImageBackground>
 *     );
 *   }
 * }
 *
 * // App registration and rendering
 * AppRegistry.registerComponent('DisplayAnImageBackground', () => DisplayAnImageBackground);
 * ```
 */
class ImageBackground extends React.Component<ImageBackgroundProps> {
  setNativeProps(props: {...}) {
    // Work-around flow
    const viewRef = this._viewRef;
    if (viewRef) {
      viewRef.setNativeProps(props);
    }
  }

  _viewRef: ?React.ElementRef<typeof View> = null;

  _captureRef = (ref: null | HostInstance) => {
    this._viewRef = ref;
  };

  render(): React.Node {
    const {
      children,
      style,
      imageStyle,
      imageRef,
      importantForAccessibility,
      ...props
    } = this.props;

    // $FlowFixMe[underconstrained-implicit-instantiation]
    const flattenedStyle = flattenStyle(style);
    return (
      <View
        accessibilityIgnoresInvertColors={true}
        importantForAccessibility={importantForAccessibility}
        style={style}
        ref={this._captureRef}>
        {/* $FlowFixMe[incompatible-use] */}
        <Image
          {...props}
          importantForAccessibility={importantForAccessibility}
          style={[
            StyleSheet.absoluteFill,
            {
              // Temporary Workaround:
              // Current (imperfect yet) implementation of <Image> overwrites width and height styles
              // (which is not quite correct), and these styles conflict with explicitly set styles
              // of <ImageBackground> and with our internal layout model here.
              // So, we have to proxy/reapply these styles explicitly for actual <Image> component.
              // This workaround should be removed after implementing proper support of
              // intrinsic content size of the <Image>.
              // $FlowFixMe[prop-missing]
              width: flattenedStyle?.width,
              // $FlowFixMe[prop-missing]
              height: flattenedStyle?.height,
            },
            imageStyle,
          ]}
          ref={imageRef}
        />
        {children}
      </View>
    );
  }
}

module.exports = ImageBackground;

Directory Contents

Dirs: 0 × Files: 70
Name Size Perms Modified Actions
305 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
6.37 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.24 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
10.57 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
10.79 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
7.92 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
306 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
465 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
3.14 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.52 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
7.11 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.47 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.12 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.81 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
3.94 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.36 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.20 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
595 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
4.93 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
406 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
440 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
424 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.69 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
430 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
414 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
609 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.76 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
302 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.16 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
569 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
841 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
299 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.51 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
364 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
3.58 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.20 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
5.74 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.85 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
295 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.38 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.42 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
51.56 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
816 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
6.15 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.01 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.10 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.04 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
276 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
380 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.69 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
8.35 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
3.13 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.84 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
707 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
3.50 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
12.22 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
844 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
15.24 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
279 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.53 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
362 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.16 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.53 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
623 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
310 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
10.67 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
2.43 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
710 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
4.22 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.30 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).