Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Flow types in all react-native source files #45786

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 2 additions & 62 deletions packages/react-native/Libraries/Blob/URL.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
}

/**
/*
* To allow Blobs be accessed via `content://` URIs,
* you need to register `BlobProvider` as a ContentProvider in your app's `AndroidManifest.xml`:
*
Expand All @@ -52,67 +52,7 @@ if (
* ```
*/

// Small subset from whatwg-url: https://github.com/jsdom/whatwg-url/tree/master/src
// The reference code bloat comes from Unicode issues with URLs, so those won't work here.
export class URLSearchParams {
_searchParams: Array<Array<string>> = [];

constructor(params: any) {
if (typeof params === 'object') {
Object.keys(params).forEach(key => this.append(key, params[key]));
}
}

append(key: string, value: string): void {
this._searchParams.push([key, value]);
}

delete(name: string): void {
throw new Error('URLSearchParams.delete is not implemented');
}

get(name: string): void {
throw new Error('URLSearchParams.get is not implemented');
}

getAll(name: string): void {
throw new Error('URLSearchParams.getAll is not implemented');
}

has(name: string): void {
throw new Error('URLSearchParams.has is not implemented');
}

set(name: string, value: string): void {
throw new Error('URLSearchParams.set is not implemented');
}

sort(): void {
throw new Error('URLSearchParams.sort is not implemented');
}

// $FlowFixMe[unsupported-syntax]
// $FlowFixMe[missing-local-annot]
[Symbol.iterator]() {
return this._searchParams[Symbol.iterator]();
}

toString(): string {
if (this._searchParams.length === 0) {
return '';
}
const last = this._searchParams.length - 1;
return this._searchParams.reduce((acc, curr, index) => {
return (
acc +
encodeURIComponent(curr[0]) +
'=' +
encodeURIComponent(curr[1]) +
(index === last ? '' : '&')
);
}, '');
}
}
export {URLSearchParams} from './URLSearchParams';

function validateBaseUrl(url: string) {
// from this MIT-licensed gist: https://gist.github.com/dperini/729294
Expand Down
71 changes: 71 additions & 0 deletions packages/react-native/Libraries/Blob/URLSearchParams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* 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.
*
* @format
* @flow
*/

// Small subset from whatwg-url: https://github.com/jsdom/whatwg-url/tree/master/src
// The reference code bloat comes from Unicode issues with URLs, so those won't work here.
export class URLSearchParams {
_searchParams: Array<Array<string>> = [];

constructor(params: any) {
if (typeof params === 'object') {
Object.keys(params).forEach(key => this.append(key, params[key]));
}
}

append(key: string, value: string): void {
this._searchParams.push([key, value]);
}

delete(name: string): void {
throw new Error('URLSearchParams.delete is not implemented');
}

get(name: string): void {
throw new Error('URLSearchParams.get is not implemented');
}

getAll(name: string): void {
throw new Error('URLSearchParams.getAll is not implemented');
}

has(name: string): void {
throw new Error('URLSearchParams.has is not implemented');
}

set(name: string, value: string): void {
throw new Error('URLSearchParams.set is not implemented');
}

sort(): void {
throw new Error('URLSearchParams.sort is not implemented');
}

// $FlowFixMe[unsupported-syntax]
// $FlowFixMe[missing-local-annot]
[Symbol.iterator]() {
return this._searchParams[Symbol.iterator]();
}

toString(): string {
if (this._searchParams.length === 0) {
return '';
}
const last = this._searchParams.length - 1;
return this._searchParams.reduce((acc, curr, index) => {
return (
acc +
encodeURIComponent(curr[0]) +
'=' +
encodeURIComponent(curr[1]) +
(index === last ? '' : '&')
);
}, '');
}
}
23 changes: 23 additions & 0 deletions packages/react-native/Libraries/Blob/URLSearchParams.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* 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.
*
* @format
* @flow
*/

declare export class URLSearchParams {
_searchParams: Array<Array<string>>;
constructor(params: any): void;
append(key: string, value: string): void;
delete(name: string): void;
get(name: string): void;
getAll(name: string): void;
has(name: string): void;
set(name: string, value: string): void;
sort(): void;
@@iterator: Iterator<Array<string>>;
toString(): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/

'use strict';

module.exports = require('../UnimplementedViews/UnimplementedView');
module.exports =
require('../UnimplementedViews/UnimplementedView') as $FlowFixMe;
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/

'use strict';

import PooledClass from './PooledClass';

const twoArgumentPooler = PooledClass.twoArgumentPooler;
Expand All @@ -19,11 +21,14 @@ const twoArgumentPooler = PooledClass.twoArgumentPooler;
* @param {number} height Height of bounding rectangle.
* @constructor BoundingDimensions
*/
function BoundingDimensions(width, height) {
// $FlowFixMe[missing-this-annot]
function BoundingDimensions(width: number, height: number) {
this.width = width;
this.height = height;
}

// $FlowFixMe[prop-missing]
// $FlowFixMe[missing-this-annot]
BoundingDimensions.prototype.destructor = function () {
this.width = null;
this.height = null;
Expand All @@ -33,13 +38,16 @@ BoundingDimensions.prototype.destructor = function () {
* @param {HTMLElement} element Element to return `BoundingDimensions` for.
* @return {BoundingDimensions} Bounding dimensions of `element`.
*/
BoundingDimensions.getPooledFromElement = function (element) {
BoundingDimensions.getPooledFromElement = function (
element: HTMLElement,
): typeof BoundingDimensions {
// $FlowFixMe[prop-missing]
return BoundingDimensions.getPooled(
element.offsetWidth,
element.offsetHeight,
);
};

PooledClass.addPoolingTo(BoundingDimensions, twoArgumentPooler);
PooledClass.addPoolingTo(BoundingDimensions as $FlowFixMe, twoArgumentPooler);

module.exports = BoundingDimensions;
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/

'use strict';

import PooledClass from './PooledClass';

const twoArgumentPooler = PooledClass.twoArgumentPooler;
Expand All @@ -20,16 +22,19 @@ const twoArgumentPooler = PooledClass.twoArgumentPooler;
* @param {number} windowStartKey Key that window starts at.
* @param {number} windowEndKey Key that window ends at.
*/
function Position(left, top) {
// $FlowFixMe[missing-this-annot]
function Position(left: number, top: number) {
this.left = left;
this.top = top;
}

// $FlowFixMe[prop-missing]
// $FlowFixMe[missing-this-annot]
Position.prototype.destructor = function () {
this.left = null;
this.top = null;
};

PooledClass.addPoolingTo(Position, twoArgumentPooler);
PooledClass.addPoolingTo(Position as $FlowFixMe, twoArgumentPooler);

module.exports = Position;
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,17 @@ const TouchableMixin = {
return;
}
this.state.touchable.positionOnActivate &&
// $FlowFixMe[prop-missing]
Position.release(this.state.touchable.positionOnActivate);
this.state.touchable.dimensionsOnActivate &&
// $FlowFixMe[prop-missing]
BoundingDimensions.release(this.state.touchable.dimensionsOnActivate);
// $FlowFixMe[prop-missing]
this.state.touchable.positionOnActivate = Position.getPooled(
globalX,
globalY,
);
// $FlowFixMe[prop-missing]
this.state.touchable.dimensionsOnActivate = BoundingDimensions.getPooled(
w,
h,
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/Libraries/Inspector/NetworkOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class NetworkOverlay extends React.Component<Props, State> {
});

XHRInterceptor.setRequestHeaderCallback((header, value, xhr) => {
// $FlowFixMe[prop-missing]
const xhrIndex = this._getRequestIndexByXHRID(xhr._index);
if (xhrIndex === -1) {
return;
Expand All @@ -159,6 +160,7 @@ class NetworkOverlay extends React.Component<Props, State> {
});

XHRInterceptor.setSendCallback((data, xhr) => {
// $FlowFixMe[prop-missing]
const xhrIndex = this._getRequestIndexByXHRID(xhr._index);
if (xhrIndex === -1) {
return;
Expand All @@ -173,6 +175,7 @@ class NetworkOverlay extends React.Component<Props, State> {

XHRInterceptor.setHeaderReceivedCallback(
(type, size, responseHeaders, xhr) => {
// $FlowFixMe[prop-missing]
const xhrIndex = this._getRequestIndexByXHRID(xhr._index);
if (xhrIndex === -1) {
return;
Expand All @@ -190,6 +193,7 @@ class NetworkOverlay extends React.Component<Props, State> {

XHRInterceptor.setResponseCallback(
(status, timeout, response, responseURL, responseType, xhr) => {
// $FlowFixMe[prop-missing]
const xhrIndex = this._getRequestIndexByXHRID(xhr._index);
if (xhrIndex === -1) {
return;
Expand Down
Loading
Loading