ImagePickerIOS.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow strict-local
  9. */
  10. 'use strict';
  11. import NativeImagePickerIOS from './NativeImagePickerIOS';
  12. import invariant from 'invariant';
  13. const ImagePickerIOS = {
  14. canRecordVideos: function(callback: (result: boolean) => void): void {
  15. invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
  16. return NativeImagePickerIOS.canRecordVideos(callback);
  17. },
  18. canUseCamera: function(callback: (result: boolean) => void): void {
  19. invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
  20. return NativeImagePickerIOS.canUseCamera(callback);
  21. },
  22. openCameraDialog: function(
  23. config: $ReadOnly<{|
  24. unmirrorFrontFacingCamera?: boolean,
  25. videoMode?: boolean,
  26. |}>,
  27. successCallback: (imageURL: string, height: number, width: number) => void,
  28. cancelCallback: () => void,
  29. ): void {
  30. invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
  31. var newConfig = {
  32. videoMode: true,
  33. unmirrorFrontFacingCamera: false,
  34. };
  35. if (config.videoMode != null) {
  36. newConfig.videoMode = config.videoMode;
  37. }
  38. if (config.unmirrorFrontFacingCamera != null) {
  39. newConfig.unmirrorFrontFacingCamera = config.unmirrorFrontFacingCamera;
  40. }
  41. return NativeImagePickerIOS.openCameraDialog(
  42. newConfig,
  43. successCallback,
  44. cancelCallback,
  45. );
  46. },
  47. openSelectDialog: function(
  48. config: $ReadOnly<{|
  49. showImages?: boolean,
  50. showVideos?: boolean,
  51. |}>,
  52. successCallback: (imageURL: string, height: number, width: number) => void,
  53. cancelCallback: () => void,
  54. ): void {
  55. invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
  56. var newConfig = {
  57. showImages: true,
  58. showVideos: false,
  59. };
  60. if (config.showImages != null) {
  61. newConfig.showImages = config.showImages;
  62. }
  63. if (config.showVideos != null) {
  64. newConfig.showVideos = config.showVideos;
  65. }
  66. return NativeImagePickerIOS.openSelectDialog(
  67. newConfig,
  68. successCallback,
  69. cancelCallback,
  70. );
  71. },
  72. /**
  73. * In iOS 13, the video URLs returned by the Image Picker are invalidated when
  74. * the picker is dismissed, unless reference to it is held. This API allows
  75. * the application to signal when it's finished with the video so that the
  76. * reference can be cleaned up.
  77. * It is safe to call this method for urlsthat aren't video URLs;
  78. * it will be a no-op.
  79. */
  80. removePendingVideo: function(url: string): void {
  81. invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
  82. NativeImagePickerIOS.removePendingVideo(url);
  83. },
  84. /**
  85. * WARNING: In most cases, removePendingVideo should be used instead because
  86. * clearAllPendingVideos could clear out pending videos made by other callers.
  87. */
  88. clearAllPendingVideos: function(): void {
  89. invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
  90. NativeImagePickerIOS.clearAllPendingVideos();
  91. },
  92. };
  93. module.exports = ImagePickerIOS;