mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
refactor(react-native-github): move ImagePickerIOS to internal (#35199)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35199 **Changelog:** [iOS][Removed] - Removed ImagePickerIOS module native sources [JS][Removed] - Removed ImagePickerIOS module from react-native Reviewed By: cortinico Differential Revision: D40859520 fbshipit-source-id: a6a114a05574d46ea62600999bff95025ba7cdc8
This commit is contained in:
committed by
Lorenzo Sciandra
parent
df737b09b1
commit
adcdb366da
Vendored
-48
@@ -1,48 +0,0 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
export interface OpenCameraDialogOptions {
|
||||
/** Defaults to false */
|
||||
videoMode?: boolean | undefined;
|
||||
}
|
||||
|
||||
export interface OpenSelectDialogOptions {
|
||||
/** Defaults to true */
|
||||
showImages?: boolean | undefined;
|
||||
/** Defaults to false */
|
||||
showVideos?: boolean | undefined;
|
||||
}
|
||||
|
||||
/** [imageURL|tempImageTag, height, width] */
|
||||
export type ImagePickerResult = [string, number, number];
|
||||
|
||||
export interface ImagePickerIOSStatic {
|
||||
canRecordVideos(callback: (value: boolean) => void): void;
|
||||
canUseCamera(callback: (value: boolean) => void): void;
|
||||
openCameraDialog(
|
||||
config: OpenCameraDialogOptions,
|
||||
successCallback: (args: ImagePickerResult) => void,
|
||||
cancelCallback: (args: any[]) => void,
|
||||
): void;
|
||||
openSelectDialog(
|
||||
config: OpenSelectDialogOptions,
|
||||
successCallback: (args: ImagePickerResult) => void,
|
||||
cancelCallback: (args: any[]) => void,
|
||||
): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* ImagePickerIOS has been extracted from react-native core and will be removed in a future release.
|
||||
* Please upgrade to use either `@react-native-community/react-native-image-picker` or 'expo-image-picker'.
|
||||
* If you cannot upgrade to a different library, please install the deprecated `@react-native-community/image-picker-ios` package.
|
||||
* @see https://github.com/react-native-community/react-native-image-picker-ios
|
||||
* @deprecated
|
||||
*/
|
||||
export const ImagePickerIOS: ImagePickerIOSStatic;
|
||||
export type ImagePickerIOS = ImagePickerIOSStatic;
|
||||
@@ -1,103 +0,0 @@
|
||||
/**
|
||||
* 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 strict-local
|
||||
*/
|
||||
|
||||
import NativeImagePickerIOS from './NativeImagePickerIOS';
|
||||
import invariant from 'invariant';
|
||||
|
||||
const ImagePickerIOS = {
|
||||
canRecordVideos: function (callback: (result: boolean) => void): void {
|
||||
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
|
||||
return NativeImagePickerIOS.canRecordVideos(callback);
|
||||
},
|
||||
canUseCamera: function (callback: (result: boolean) => void): void {
|
||||
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
|
||||
return NativeImagePickerIOS.canUseCamera(callback);
|
||||
},
|
||||
openCameraDialog: function (
|
||||
config: $ReadOnly<{|
|
||||
unmirrorFrontFacingCamera?: boolean,
|
||||
videoMode?: boolean,
|
||||
|}>,
|
||||
successCallback: (imageURL: string, height: number, width: number) => void,
|
||||
cancelCallback: () => void,
|
||||
): void {
|
||||
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
|
||||
|
||||
var newConfig = {
|
||||
videoMode: true,
|
||||
unmirrorFrontFacingCamera: false,
|
||||
};
|
||||
|
||||
if (config.videoMode != null) {
|
||||
newConfig.videoMode = config.videoMode;
|
||||
}
|
||||
|
||||
if (config.unmirrorFrontFacingCamera != null) {
|
||||
newConfig.unmirrorFrontFacingCamera = config.unmirrorFrontFacingCamera;
|
||||
}
|
||||
|
||||
return NativeImagePickerIOS.openCameraDialog(
|
||||
newConfig,
|
||||
successCallback,
|
||||
cancelCallback,
|
||||
);
|
||||
},
|
||||
openSelectDialog: function (
|
||||
config: $ReadOnly<{|
|
||||
showImages?: boolean,
|
||||
showVideos?: boolean,
|
||||
|}>,
|
||||
successCallback: (imageURL: string, height: number, width: number) => void,
|
||||
cancelCallback: () => void,
|
||||
): void {
|
||||
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
|
||||
|
||||
var newConfig = {
|
||||
showImages: true,
|
||||
showVideos: false,
|
||||
};
|
||||
|
||||
if (config.showImages != null) {
|
||||
newConfig.showImages = config.showImages;
|
||||
}
|
||||
|
||||
if (config.showVideos != null) {
|
||||
newConfig.showVideos = config.showVideos;
|
||||
}
|
||||
|
||||
return NativeImagePickerIOS.openSelectDialog(
|
||||
newConfig,
|
||||
successCallback,
|
||||
cancelCallback,
|
||||
);
|
||||
},
|
||||
/**
|
||||
* In iOS 13, the video URLs returned by the Image Picker are invalidated when
|
||||
* the picker is dismissed, unless reference to it is held. This API allows
|
||||
* the application to signal when it's finished with the video so that the
|
||||
* reference can be cleaned up.
|
||||
* It is safe to call this method for urlsthat aren't video URLs;
|
||||
* it will be a no-op.
|
||||
*/
|
||||
removePendingVideo: function (url: string): void {
|
||||
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
|
||||
NativeImagePickerIOS.removePendingVideo(url);
|
||||
},
|
||||
/**
|
||||
* WARNING: In most cases, removePendingVideo should be used instead because
|
||||
* clearAllPendingVideos could clear out pending videos made by other callers.
|
||||
*/
|
||||
clearAllPendingVideos: function (): void {
|
||||
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
|
||||
NativeImagePickerIOS.clearAllPendingVideos();
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = ImagePickerIOS;
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* 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
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type {TurboModule} from '../TurboModule/RCTExport';
|
||||
|
||||
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getConstants: () => {||};
|
||||
+canRecordVideos: (callback: (result: boolean) => void) => void;
|
||||
+canUseCamera: (callback: (result: boolean) => void) => void;
|
||||
+openCameraDialog: (
|
||||
config: {|
|
||||
unmirrorFrontFacingCamera: boolean,
|
||||
videoMode: boolean,
|
||||
|},
|
||||
successCallback: (imageURL: string, height: number, width: number) => void,
|
||||
cancelCallback: () => void,
|
||||
) => void;
|
||||
+openSelectDialog: (
|
||||
config: {|
|
||||
showImages: boolean,
|
||||
showVideos: boolean,
|
||||
|},
|
||||
successCallback: (imageURL: string, height: number, width: number) => void,
|
||||
cancelCallback: () => void,
|
||||
) => void;
|
||||
+clearAllPendingVideos: () => void;
|
||||
+removePendingVideo: (url: string) => void;
|
||||
}
|
||||
|
||||
export default (TurboModuleRegistry.get<Spec>('ImagePickerIOS'): ?Spec);
|
||||
@@ -59,7 +59,6 @@ import typeof Dimensions from './Libraries/Utilities/Dimensions';
|
||||
import typeof Easing from './Libraries/Animated/Easing';
|
||||
import typeof ReactNative from './Libraries/Renderer/shims/ReactNative';
|
||||
import typeof I18nManager from './Libraries/ReactNative/I18nManager';
|
||||
import typeof ImagePickerIOS from './Libraries/Image/ImagePickerIOS';
|
||||
import typeof InteractionManager from './Libraries/Interaction/InteractionManager';
|
||||
import typeof Keyboard from './Libraries/Components/Keyboard/Keyboard';
|
||||
import typeof LayoutAnimation from './Libraries/LayoutAnimation/LayoutAnimation';
|
||||
@@ -281,16 +280,6 @@ module.exports = {
|
||||
get I18nManager(): I18nManager {
|
||||
return require('./Libraries/ReactNative/I18nManager');
|
||||
},
|
||||
get ImagePickerIOS(): ImagePickerIOS {
|
||||
warnOnce(
|
||||
'imagePickerIOS-moved',
|
||||
'ImagePickerIOS has been extracted from react-native core and will be removed in a future release. ' +
|
||||
"Please upgrade to use either '@react-native-community/react-native-image-picker' or 'expo-image-picker'. " +
|
||||
"If you cannot upgrade to a different library, please install the deprecated '@react-native-community/image-picker-ios' package. " +
|
||||
'See https://github.com/rnc-archive/react-native-image-picker-ios',
|
||||
);
|
||||
return require('./Libraries/Image/ImagePickerIOS');
|
||||
},
|
||||
get InteractionManager(): InteractionManager {
|
||||
return require('./Libraries/Interaction/InteractionManager');
|
||||
},
|
||||
@@ -765,4 +754,20 @@ if (__DEV__) {
|
||||
);
|
||||
},
|
||||
});
|
||||
/* $FlowFixMe[prop-missing] This is intentional: Flow will error when
|
||||
* attempting to access ImagePickerIOS. */
|
||||
/* $FlowFixMe[invalid-export] This is intentional: Flow will error when
|
||||
* attempting to access ImagePickerIOS. */
|
||||
Object.defineProperty(module.exports, 'ImagePickerIOS', {
|
||||
configurable: true,
|
||||
get() {
|
||||
invariant(
|
||||
false,
|
||||
'ImagePickerIOS has been removed from React Native. ' +
|
||||
"Please upgrade to use either '@react-native-community/react-native-image-picker' or 'expo-image-picker'. " +
|
||||
"If you cannot upgrade to a different library, please install the deprecated '@react-native-community/image-picker-ios' package. " +
|
||||
'See https://github.com/rnc-archive/react-native-image-picker-ios',
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
-67
@@ -1224,73 +1224,6 @@ const REAL_MODULE_EXAMPLE: SchemaType = {
|
||||
},
|
||||
moduleNames: ['CameraRollManager'],
|
||||
},
|
||||
NativeImagePickerIOS: {
|
||||
type: 'NativeModule',
|
||||
aliases: {},
|
||||
spec: {
|
||||
properties: [
|
||||
{
|
||||
name: 'openCameraDialog',
|
||||
optional: false,
|
||||
typeAnnotation: {
|
||||
type: 'FunctionTypeAnnotation',
|
||||
returnTypeAnnotation: {
|
||||
type: 'VoidTypeAnnotation',
|
||||
},
|
||||
params: [
|
||||
{
|
||||
optional: false,
|
||||
name: 'config',
|
||||
typeAnnotation: {
|
||||
type: 'ObjectTypeAnnotation',
|
||||
properties: [
|
||||
{
|
||||
optional: false,
|
||||
name: 'unmirrorFrontFacingCamera',
|
||||
typeAnnotation: {
|
||||
type: 'BooleanTypeAnnotation',
|
||||
},
|
||||
},
|
||||
{
|
||||
optional: false,
|
||||
name: 'videoMode',
|
||||
typeAnnotation: {
|
||||
type: 'BooleanTypeAnnotation',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'successCallback',
|
||||
optional: false,
|
||||
typeAnnotation: {
|
||||
type: 'FunctionTypeAnnotation',
|
||||
params: [],
|
||||
returnTypeAnnotation: {
|
||||
type: 'VoidTypeAnnotation',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'cancelCallback',
|
||||
optional: false,
|
||||
typeAnnotation: {
|
||||
type: 'FunctionTypeAnnotation',
|
||||
params: [],
|
||||
returnTypeAnnotation: {
|
||||
type: 'VoidTypeAnnotation',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
moduleNames: ['ImagePickerIOS'],
|
||||
excludedPlatforms: ['android'],
|
||||
},
|
||||
NativeExceptionsManager: {
|
||||
type: 'NativeModule',
|
||||
aliases: {
|
||||
|
||||
-9
@@ -240,15 +240,6 @@ NativeCameraRollManagerCxxSpecJSI::NativeCameraRollManagerCxxSpecJSI(std::shared
|
||||
methodMap_[\\"saveToCameraRoll\\"] = MethodMetadata {2, __hostFunction_NativeCameraRollManagerCxxSpecJSI_saveToCameraRoll};
|
||||
methodMap_[\\"deletePhotos\\"] = MethodMetadata {1, __hostFunction_NativeCameraRollManagerCxxSpecJSI_deletePhotos};
|
||||
}
|
||||
static jsi::Value __hostFunction_NativeImagePickerIOSCxxSpecJSI_openCameraDialog(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
static_cast<NativeImagePickerIOSCxxSpecJSI *>(&turboModule)->openCameraDialog(rt, args[0].asObject(rt), args[1].asObject(rt).asFunction(rt), args[2].asObject(rt).asFunction(rt));
|
||||
return jsi::Value::undefined();
|
||||
}
|
||||
|
||||
NativeImagePickerIOSCxxSpecJSI::NativeImagePickerIOSCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
|
||||
: TurboModule(\\"ImagePickerIOS\\", jsInvoker) {
|
||||
methodMap_[\\"openCameraDialog\\"] = MethodMetadata {3, __hostFunction_NativeImagePickerIOSCxxSpecJSI_openCameraDialog};
|
||||
}
|
||||
static jsi::Value __hostFunction_NativeExceptionsManagerCxxSpecJSI_reportFatalException(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
static_cast<NativeExceptionsManagerCxxSpecJSI *>(&turboModule)->reportFatalException(rt, args[0].asString(rt), args[1].asObject(rt).asArray(rt), args[2].asNumber());
|
||||
return jsi::Value::undefined();
|
||||
|
||||
-43
@@ -505,49 +505,6 @@ private:
|
||||
Delegate delegate_;
|
||||
};
|
||||
|
||||
class JSI_EXPORT NativeImagePickerIOSCxxSpecJSI : public TurboModule {
|
||||
protected:
|
||||
NativeImagePickerIOSCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
|
||||
|
||||
public:
|
||||
virtual void openCameraDialog(jsi::Runtime &rt, jsi::Object config, jsi::Function successCallback, jsi::Function cancelCallback) = 0;
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class JSI_EXPORT NativeImagePickerIOSCxxSpec : public TurboModule {
|
||||
public:
|
||||
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
|
||||
return delegate_.get(rt, propName);
|
||||
}
|
||||
|
||||
protected:
|
||||
NativeImagePickerIOSCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
|
||||
: TurboModule(\\"ImagePickerIOS\\", jsInvoker),
|
||||
delegate_(static_cast<T*>(this), jsInvoker) {}
|
||||
|
||||
private:
|
||||
class Delegate : public NativeImagePickerIOSCxxSpecJSI {
|
||||
public:
|
||||
Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
|
||||
NativeImagePickerIOSCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {}
|
||||
|
||||
void openCameraDialog(jsi::Runtime &rt, jsi::Object config, jsi::Function successCallback, jsi::Function cancelCallback) override {
|
||||
static_assert(
|
||||
bridging::getParameterCount(&T::openCameraDialog) == 4,
|
||||
\\"Expected openCameraDialog(...) to have 4 parameters\\");
|
||||
|
||||
return bridging::callFromJs<void>(
|
||||
rt, &T::openCameraDialog, jsInvoker_, instance_, std::move(config), std::move(successCallback), std::move(cancelCallback));
|
||||
}
|
||||
|
||||
private:
|
||||
T *instance_;
|
||||
};
|
||||
|
||||
Delegate delegate_;
|
||||
};
|
||||
|
||||
class JSI_EXPORT NativeExceptionsManagerCxxSpecJSI : public TurboModule {
|
||||
protected:
|
||||
NativeExceptionsManagerCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
|
||||
|
||||
-44
@@ -711,40 +711,6 @@ namespace facebook {
|
||||
};
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
namespace JS {
|
||||
namespace NativeImagePickerIOS {
|
||||
struct SpecOpenCameraDialogConfig {
|
||||
bool unmirrorFrontFacingCamera() const;
|
||||
bool videoMode() const;
|
||||
|
||||
SpecOpenCameraDialogConfig(NSDictionary *const v) : _v(v) {}
|
||||
private:
|
||||
NSDictionary *_v;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@interface RCTCxxConvert (NativeImagePickerIOS_SpecOpenCameraDialogConfig)
|
||||
+ (RCTManagedPointer *)JS_NativeImagePickerIOS_SpecOpenCameraDialogConfig:(id)json;
|
||||
@end
|
||||
@protocol NativeImagePickerIOSSpec <RCTBridgeModule, RCTTurboModule>
|
||||
|
||||
- (void)openCameraDialog:(JS::NativeImagePickerIOS::SpecOpenCameraDialogConfig &)config
|
||||
successCallback:(RCTResponseSenderBlock)successCallback
|
||||
cancelCallback:(RCTResponseSenderBlock)cancelCallback;
|
||||
|
||||
@end
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
/**
|
||||
* ObjC++ class for module 'NativeImagePickerIOS'
|
||||
*/
|
||||
class JSI_EXPORT NativeImagePickerIOSSpecJSI : public ObjCTurboModule {
|
||||
public:
|
||||
NativeImagePickerIOSSpecJSI(const ObjCTurboModule::InitParams ¶ms);
|
||||
};
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
inline double JS::NativeCameraRollManager::GetPhotosParams::first() const
|
||||
{
|
||||
id const p = _v[@\\"first\\"];
|
||||
@@ -845,16 +811,6 @@ inline id<NSObject> _Nullable JS::NativeExceptionsManager::ExceptionData::extraD
|
||||
id const p = _v[@\\"extraData\\"];
|
||||
return p;
|
||||
}
|
||||
inline bool JS::NativeImagePickerIOS::SpecOpenCameraDialogConfig::unmirrorFrontFacingCamera() const
|
||||
{
|
||||
id const p = _v[@\\"unmirrorFrontFacingCamera\\"];
|
||||
return RCTBridgingToBool(p);
|
||||
}
|
||||
inline bool JS::NativeImagePickerIOS::SpecOpenCameraDialogConfig::videoMode() const
|
||||
{
|
||||
id const p = _v[@\\"videoMode\\"];
|
||||
return RCTBridgingToBool(p);
|
||||
}
|
||||
",
|
||||
}
|
||||
`;
|
||||
|
||||
-21
@@ -367,27 +367,6 @@ namespace facebook {
|
||||
}
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@implementation RCTCxxConvert (NativeImagePickerIOS_SpecOpenCameraDialogConfig)
|
||||
+ (RCTManagedPointer *)JS_NativeImagePickerIOS_SpecOpenCameraDialogConfig:(id)json
|
||||
{
|
||||
return facebook::react::managedPointer<JS::NativeImagePickerIOS::SpecOpenCameraDialogConfig>(json);
|
||||
}
|
||||
@end
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeImagePickerIOSSpecJSI_openCameraDialog(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, \\"openCameraDialog\\", @selector(openCameraDialog:successCallback:cancelCallback:), args, count);
|
||||
}
|
||||
|
||||
NativeImagePickerIOSSpecJSI::NativeImagePickerIOSSpecJSI(const ObjCTurboModule::InitParams ¶ms)
|
||||
: ObjCTurboModule(params) {
|
||||
|
||||
methodMap_[\\"openCameraDialog\\"] = MethodMetadata {3, __hostFunction_NativeImagePickerIOSSpecJSI_openCameraDialog};
|
||||
setMethodArgConversionSelector(@\\"openCameraDialog\\", 0, @\\"JS_NativeImagePickerIOS_SpecOpenCameraDialogConfig:\\");
|
||||
}
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
",
|
||||
}
|
||||
`;
|
||||
|
||||
Vendored
-1
@@ -110,7 +110,6 @@ export * from '../Libraries/EventEmitter/NativeEventEmitter';
|
||||
export * from '../Libraries/EventEmitter/RCTDeviceEventEmitter';
|
||||
export * from '../Libraries/EventEmitter/RCTNativeAppEventEmitter';
|
||||
export * from '../Libraries/Image/Image';
|
||||
export * from '../Libraries/Image/ImagePickerIOS';
|
||||
export * from '../Libraries/Image/ImageResizeMode';
|
||||
export * from '../Libraries/Image/ImageSource';
|
||||
export * from '../Libraries/Interaction/InteractionManager';
|
||||
|
||||
Reference in New Issue
Block a user