From 0cd505129925a9c76fa7d2fb444547883c89a8a7 Mon Sep 17 00:00:00 2001 From: Alexey Nesterov Date: Fri, 26 Apr 2024 15:59:30 +0700 Subject: [PATCH] #34 Add OptIn annotations --- .../kotlin/dev/icerock/moko/media/test/createBitmapMock.kt | 2 ++ media/src/iosMain/kotlin/dev/icerock/moko/media/Bitmap.kt | 6 ++++-- .../iosMain/kotlin/dev/icerock/moko/media/FileMediaExt.kt | 2 ++ .../moko/media/picker/ImagePickerDelegateToContinuation.kt | 2 ++ .../icerock/moko/media/picker/ios/MediaPickerController.kt | 2 ++ .../dev/icerock/moko/media/player/MediaPlayerController.kt | 2 ++ sample/ios-app/Podfile | 2 +- 7 files changed, 15 insertions(+), 3 deletions(-) diff --git a/media-test/src/iosMain/kotlin/dev/icerock/moko/media/test/createBitmapMock.kt b/media-test/src/iosMain/kotlin/dev/icerock/moko/media/test/createBitmapMock.kt index f70fae8..751995a 100644 --- a/media-test/src/iosMain/kotlin/dev/icerock/moko/media/test/createBitmapMock.kt +++ b/media-test/src/iosMain/kotlin/dev/icerock/moko/media/test/createBitmapMock.kt @@ -5,10 +5,12 @@ package dev.icerock.moko.media.test import dev.icerock.moko.media.Bitmap +import kotlinx.cinterop.ExperimentalForeignApi import platform.CoreGraphics.CGRectMake import platform.CoreImage.CIImage import platform.UIKit.UIImage +@OptIn(ExperimentalForeignApi::class) actual fun createBitmapMock(): Bitmap { val image = CIImage.clearImage.imageByCroppingToRect(CGRectMake(0.0, 0.0, 1.0, 1.0)) return Bitmap(UIImage(image)) diff --git a/media/src/iosMain/kotlin/dev/icerock/moko/media/Bitmap.kt b/media/src/iosMain/kotlin/dev/icerock/moko/media/Bitmap.kt index e575ae4..91906a9 100755 --- a/media/src/iosMain/kotlin/dev/icerock/moko/media/Bitmap.kt +++ b/media/src/iosMain/kotlin/dev/icerock/moko/media/Bitmap.kt @@ -6,6 +6,7 @@ package dev.icerock.moko.media import kotlinx.cinterop.ByteVar import kotlinx.cinterop.CPointer +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.get import kotlinx.cinterop.reinterpret import kotlinx.cinterop.useContents @@ -18,6 +19,7 @@ import platform.UIKit.UIGraphicsGetImageFromCurrentImageContext import platform.UIKit.UIImage import platform.UIKit.UIImageJPEGRepresentation +@OptIn(ExperimentalForeignApi::class) actual class Bitmap(val image: UIImage) { actual fun toByteArray(): ByteArray { @@ -34,7 +36,7 @@ actual class Bitmap(val image: UIImage) { val imageData = UIImageJPEGRepresentation(image, COMPRESSION_QUALITY) ?: throw IllegalArgumentException("image data is null") - return imageData.base64EncodedStringWithOptions(0) + return imageData.base64EncodedStringWithOptions(0u) } actual fun toBase64WithCompress(maxSize: Int): String { @@ -54,7 +56,7 @@ actual class Bitmap(val image: UIImage) { val imageData = UIImageJPEGRepresentation(newImage!!, COMPRESSION_QUALITY) ?: throw IllegalArgumentException("image data is null") - return imageData.base64EncodedStringWithOptions(0) + return imageData.base64EncodedStringWithOptions(0u) } private companion object { diff --git a/media/src/iosMain/kotlin/dev/icerock/moko/media/FileMediaExt.kt b/media/src/iosMain/kotlin/dev/icerock/moko/media/FileMediaExt.kt index 0df3f7c..4a0d58a 100644 --- a/media/src/iosMain/kotlin/dev/icerock/moko/media/FileMediaExt.kt +++ b/media/src/iosMain/kotlin/dev/icerock/moko/media/FileMediaExt.kt @@ -6,6 +6,7 @@ package dev.icerock.moko.media import kotlinx.cinterop.ByteVar import kotlinx.cinterop.CPointer +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.get import kotlinx.cinterop.reinterpret import platform.Foundation.NSData @@ -18,6 +19,7 @@ fun FileMedia.toNSData(): NSData { return NSData.dataWithContentsOfURL(url) ?: throw IllegalArgumentException("invalid file data") } +@OptIn(ExperimentalForeignApi::class) actual fun FileMedia.toByteArray(): ByteArray { val data = toNSData() val bytes = data.bytes ?: throw IllegalArgumentException("file bytes is null") diff --git a/media/src/iosMain/kotlin/dev/icerock/moko/media/picker/ImagePickerDelegateToContinuation.kt b/media/src/iosMain/kotlin/dev/icerock/moko/media/picker/ImagePickerDelegateToContinuation.kt index e3ee900..1ba6aca 100644 --- a/media/src/iosMain/kotlin/dev/icerock/moko/media/picker/ImagePickerDelegateToContinuation.kt +++ b/media/src/iosMain/kotlin/dev/icerock/moko/media/picker/ImagePickerDelegateToContinuation.kt @@ -8,6 +8,7 @@ import dev.icerock.moko.media.Bitmap import dev.icerock.moko.media.Media import dev.icerock.moko.media.MediaType import dev.icerock.moko.media.picker.ios.MediaPickerController +import kotlinx.cinterop.ExperimentalForeignApi import platform.AVFoundation.AVAsset import platform.AVFoundation.AVAssetImageGenerator import platform.AVFoundation.AVURLAsset @@ -91,6 +92,7 @@ internal class ImagePickerDelegateToContinuation constructor( } // Стоит сделать асинхронно и придумать что делать с ошибкой + @OptIn(ExperimentalForeignApi::class) private fun fetchThumbnail(videoAsset: AVAsset): UIImage { val imageGenerator = AVAssetImageGenerator( asset = videoAsset diff --git a/media/src/iosMain/kotlin/dev/icerock/moko/media/picker/ios/MediaPickerController.kt b/media/src/iosMain/kotlin/dev/icerock/moko/media/picker/ios/MediaPickerController.kt index a739899..2d135c5 100644 --- a/media/src/iosMain/kotlin/dev/icerock/moko/media/picker/ios/MediaPickerController.kt +++ b/media/src/iosMain/kotlin/dev/icerock/moko/media/picker/ios/MediaPickerController.kt @@ -15,6 +15,7 @@ import dev.icerock.moko.media.picker.ImagePickerDelegateToContinuation import dev.icerock.moko.media.picker.MediaSource import dev.icerock.moko.permissions.Permission import dev.icerock.moko.permissions.PermissionsController +import kotlinx.cinterop.ExperimentalForeignApi import platform.CoreServices.kUTTypeData import platform.CoreServices.kUTTypeImage import platform.CoreServices.kUTTypeMovie @@ -155,6 +156,7 @@ class MediaPickerController( return media } + @OptIn(ExperimentalForeignApi::class) internal companion object { val kVideoType = CFBridgingRelease(kUTTypeVideo) as String val kMovieType = CFBridgingRelease(kUTTypeMovie) as String diff --git a/media/src/iosMain/kotlin/dev/icerock/moko/media/player/MediaPlayerController.kt b/media/src/iosMain/kotlin/dev/icerock/moko/media/player/MediaPlayerController.kt index 817cfc3..08af197 100755 --- a/media/src/iosMain/kotlin/dev/icerock/moko/media/player/MediaPlayerController.kt +++ b/media/src/iosMain/kotlin/dev/icerock/moko/media/player/MediaPlayerController.kt @@ -4,6 +4,7 @@ package dev.icerock.moko.media.player +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.cValue import platform.AVFoundation.AVPlayer import platform.AVFoundation.AVPlayerItemDidPlayToEndTimeNotification @@ -72,6 +73,7 @@ actual class MediaPlayerController { player?.pause() } + @OptIn(ExperimentalForeignApi::class) actual fun stop() { player?.run { pause() diff --git a/sample/ios-app/Podfile b/sample/ios-app/Podfile index 0aed8c9..2ec0fba 100644 --- a/sample/ios-app/Podfile +++ b/sample/ios-app/Podfile @@ -4,7 +4,7 @@ source 'https://cdn.cocoapods.org/' inhibit_all_warnings! use_frameworks! -platform :ios, '11.0' +platform :ios, '12.0' # workaround for https://github.com/CocoaPods/CocoaPods/issues/8073 # need for correct invalidate of cache MultiPlatformLibrary.framework install! 'cocoapods', :disable_input_output_paths => true