Skip to content

Commit 4d917c8

Browse files
RSNarafacebook-github-bot
authored andcommitted
Additional Flow changes to files that use this component
Summary: This diff includes: 1. Touchups to the `CameraRollView` typings. 2. Typings for `CameraRollViewExmaple`. 3. Flow fixes for internal callsites. Reviewed By: yungsters Differential Revision: D10362686 fbshipit-source-id: 48bf3fba0566e9c5c062aee3342d669f6c143d9f
1 parent 8465094 commit 4d917c8

File tree

4 files changed

+50
-24
lines changed

4 files changed

+50
-24
lines changed

Libraries/CameraRoll/CameraRoll.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ const ASSET_TYPE_OPTIONS = {
3232
Photos: 'Photos',
3333
};
3434

35-
type GetPhotosParams = {
35+
export type GroupTypes = $Keys<typeof GROUP_TYPES_OPTIONS>;
36+
37+
export type GetPhotosParams = {
3638
first: number,
3739
after?: string,
38-
groupTypes?: $Keys<typeof GROUP_TYPES_OPTIONS>,
40+
groupTypes?: GroupTypes,
3941
groupName?: string,
4042
assetType?: $Keys<typeof ASSET_TYPE_OPTIONS>,
4143
mimeTypes?: Array<string>,
@@ -84,6 +86,7 @@ export type PhotoIdentifier = {
8486
type: string,
8587
group_name: string,
8688
image: {
89+
filename: string,
8790
uri: string,
8891
height: number,
8992
width: number,
@@ -153,8 +156,8 @@ const getPhotosReturnChecker = deprecatedCreateStrictShapeTypeChecker({
153156
* See https://facebook.github.io/react-native/docs/cameraroll.html
154157
*/
155158
class CameraRoll {
156-
static GroupTypesOptions: Object = GROUP_TYPES_OPTIONS;
157-
static AssetTypeOptions: Object = ASSET_TYPE_OPTIONS;
159+
static GroupTypesOptions = GROUP_TYPES_OPTIONS;
160+
static AssetTypeOptions = ASSET_TYPE_OPTIONS;
158161

159162
/**
160163
* `CameraRoll.saveImageWithTag()` is deprecated. Use `CameraRoll.saveToCameraRoll()` instead.

RNTester/js/AssetScaledImageExample.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@ var React = require('react');
1414
var ReactNative = require('react-native');
1515
var {Image, StyleSheet, View, ScrollView} = ReactNative;
1616

17-
class AssetScaledImageExample extends React.Component<
18-
$FlowFixMeProps,
19-
$FlowFixMeState,
20-
> {
17+
import type {PhotoIdentifier} from 'CameraRoll';
18+
19+
type Props = $ReadOnly<{|
20+
asset: PhotoIdentifier,
21+
|}>;
22+
23+
type State = {|
24+
asset: PhotoIdentifier,
25+
|};
26+
27+
class AssetScaledImageExample extends React.Component<Props, State> {
2128
state = {
2229
asset: this.props.asset,
2330
};

RNTester/js/CameraRollExample.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,32 @@ const CameraRollView = require('./CameraRollView');
2828

2929
const AssetScaledImageExampleView = require('./AssetScaledImageExample');
3030

31-
import type {PhotoIdentifier} from 'CameraRoll';
31+
import type {PhotoIdentifier, GroupTypes} from 'CameraRoll';
3232

33-
class CameraRollExample extends React.Component<
34-
$FlowFixMeProps,
35-
$FlowFixMeState,
36-
> {
33+
type Props = $ReadOnly<{|
34+
navigator?: ?Array<
35+
$ReadOnly<{|
36+
title: string,
37+
component: Class<React.Component<any, any>>,
38+
backButtonTitle: string,
39+
passProps: $ReadOnly<{|asset: PhotoIdentifier|}>,
40+
|}>,
41+
>,
42+
|}>;
43+
44+
type State = {|
45+
groupTypes: GroupTypes,
46+
sliderValue: number,
47+
bigImages: boolean,
48+
|};
49+
50+
class CameraRollExample extends React.Component<Props, State> {
3751
state = {
3852
groupTypes: 'SavedPhotos',
3953
sliderValue: 1,
4054
bigImages: true,
4155
};
42-
_cameraRollView: ?CameraRollView;
56+
_cameraRollView: ?React.ElementRef<typeof CameraRollView>;
4357
render() {
4458
return (
4559
<View>
@@ -139,7 +153,7 @@ exports.description =
139153
exports.examples = [
140154
{
141155
title: 'Photos',
142-
render(): React.Element<any> {
156+
render(): React.Node {
143157
return <CameraRollExample />;
144158
},
145159
},

RNTester/js/CameraRollView.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ const ListViewDataSource = require('ListViewDataSource');
2828
const groupByEveryN = require('groupByEveryN');
2929
const logError = require('logError');
3030

31-
import type {PhotoIdentifier, PhotoIdentifiersPage} from 'CameraRoll';
31+
import type {
32+
PhotoIdentifier,
33+
PhotoIdentifiersPage,
34+
GetPhotosParams,
35+
} from 'CameraRoll';
3236

33-
const rowHasChanged = function(r1: Array<Image>, r2: Array<Image>): boolean {
37+
function rowHasChanged<T>(r1: Array<T>, r2: Array<T>): boolean {
3438
if (r1.length !== r2.length) {
3539
return true;
3640
}
@@ -42,9 +46,9 @@ const rowHasChanged = function(r1: Array<Image>, r2: Array<Image>): boolean {
4246
}
4347

4448
return false;
45-
};
49+
}
4650

47-
type PropsObject = {|
51+
type Props = $ReadOnly<{|
4852
/**
4953
* The group where the photos will be fetched from. Possible
5054
* values are 'Album', 'All', 'Event', 'Faces', 'Library', 'PhotoStream'
@@ -79,9 +83,7 @@ type PropsObject = {|
7983
* The asset type, one of 'Photos', 'Videos' or 'All'
8084
*/
8185
assetType: 'Photos' | 'Videos' | 'All',
82-
|};
83-
84-
type Props = $ReadOnly<PropsObject>;
86+
|}>;
8587

8688
type State = {|
8789
assets: Array<PhotoIdentifier>,
@@ -131,7 +133,7 @@ class CameraRollView extends React.Component<Props, State> {
131133
this.fetch();
132134
}
133135

134-
UNSAFE_componentWillReceiveProps(nextProps: $Shape<PropsObject>) {
136+
UNSAFE_componentWillReceiveProps(nextProps: Props) {
135137
if (this.props.groupTypes !== nextProps.groupTypes) {
136138
this.fetch(true);
137139
}
@@ -157,7 +159,7 @@ class CameraRollView extends React.Component<Props, State> {
157159
}
158160
}
159161

160-
const fetchParams: Object = {
162+
const fetchParams: GetPhotosParams = {
161163
first: this.props.batchSize,
162164
groupTypes: this.props.groupTypes,
163165
assetType: this.props.assetType,

0 commit comments

Comments
 (0)