Commit Graph

3 Commits

Author SHA1 Message Date
Adam Comella ee8496f364 iOS: Support HTTP headers for source prop on <Image> components
Summary:
Allows developers to specify headers to include in the HTTP request
when fetching a remote image. For example, one might leverage this
when fetching an image from an endpoint that requires authentication:

```
<Image
  style={styles.logo}
  source={{
    uri: 'http://facebook.github.io/react/img/logo_og.png',
    headers: {
      Authorization: 'someAuthToken'
    }
  }}
/>
```

Note that the header values must be strings.

Works on iOS and Android.

**Test plan (required)**

- Ran a small example like the one above on iOS and Android and ensured the headers were sent to the server.
- Ran a small example to ensure that \<Image\> components without headers still work.
- Currently using this code in our app.

Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/7338

Reviewed By: javache

Differential Revision: D3371458

Pulled By: nicklockwood

fbshipit-source-id: cdb24fe2572c3ae3ba82c86ad383af6d85157e20
2016-06-01 10:43:28 -07:00
Gaëtan Renaudeau f940e7c4a6 iOS: Fix Image source={{ uri: null }} to crash
Summary:
this is a recent regression because the error appeared in my app (from 0.16 to 0.17).

```
<Image source={{ uri: null }} />
```

will make an error:

```
[RCTConvert.m:55] Error setting property 'source' of RCTImageView with tag #317: JSON value '<null>' of type NSNull cannot be converted to NSString
```

The solution attached is to check that uri is a NSString and return nil if not (the same way nil is returned in case of invalid url).
Closes https://github.com/facebook/react-native/pull/4902

Reviewed By: svcscm

Differential Revision: D2779789

Pulled By: nicklockwood

fb-gh-sync-id: cfe429ec5e53e63b7b368c06e693424ca8aaa11e
2015-12-21 10:04:31 -08:00
Nick Lockwood b672294858 Added RCTImageSource
Summary:
public

The +[RCTConvert UIImage:] function, while convenient, is inherently limited by being synchronous, which means that it cannot be used to load remote images, and may not be efficient for local images either. It's also unable to access the bridge, which means that it cannot take advantage of the modular image-loading pipeline.

This diff introduces a new RCTImageSource class which can be used to pass image source objects over the bridge and defer loading until later.

I've also added automatic application of the `resolveAssetSource()` function based on prop type, and fixed up the image logic in NavigatorIOS and TabBarIOS.

Reviewed By: javache

Differential Revision: D2631541

fb-gh-sync-id: 6604635e8bb5394425102487f1ee7cd729321877
2015-12-08 03:32:30 -08:00