Skip to content

Commit

Permalink
Add OptIn annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Nesterov committed Apr 26, 2024
1 parent 7a66558 commit 5c0defb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions media/src/iosMain/kotlin/dev/icerock/moko/media/Bitmap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,6 +92,7 @@ internal class ImagePickerDelegateToContinuation constructor(
}

// Стоит сделать асинхронно и придумать что делать с ошибкой
@OptIn(ExperimentalForeignApi::class)
private fun fetchThumbnail(videoAsset: AVAsset): UIImage {
val imageGenerator = AVAssetImageGenerator(
asset = videoAsset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,6 +73,7 @@ actual class MediaPlayerController {
player?.pause()
}

@OptIn(ExperimentalForeignApi::class)
actual fun stop() {
player?.run {
pause()
Expand Down
2 changes: 1 addition & 1 deletion sample/ios-app/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c0defb

Please sign in to comment.