diff options
author | Hailey <me@haileyok.com> | 2024-07-11 18:15:35 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-11 18:15:35 -0700 |
commit | 2397104ad6169ced02b1acd9fbbbe426f4cc4da0 (patch) | |
tree | e6aaa5f0b3acaa2acb06880cba6c7703b7ac7b0c /modules/expo-bluesky-gif-view | |
parent | b433469ab954db846ab7bb9109cfe7262711c5bb (diff) | |
download | voidsky-2397104ad6169ced02b1acd9fbbbe426f4cc4da0.tar.zst |
Lint native files (#4768)
Diffstat (limited to 'modules/expo-bluesky-gif-view')
5 files changed, 132 insertions, 126 deletions
diff --git a/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/AppCompatImageViewExtended.kt b/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/AppCompatImageViewExtended.kt index 5d2084845..5ba5ccf71 100644 --- a/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/AppCompatImageViewExtended.kt +++ b/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/AppCompatImageViewExtended.kt @@ -5,7 +5,10 @@ import android.graphics.Canvas import android.graphics.drawable.Animatable import androidx.appcompat.widget.AppCompatImageView -class AppCompatImageViewExtended(context: Context, private val parent: GifView): AppCompatImageView(context) { +class AppCompatImageViewExtended( + context: Context, + private val parent: GifView, +) : AppCompatImageView(context) { override fun onDraw(canvas: Canvas) { super.onDraw(canvas) @@ -34,4 +37,4 @@ class AppCompatImageViewExtended(context: Context, private val parent: GifView): drawable.start() } } -} \ No newline at end of file +} diff --git a/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/ExpoBlueskyGifViewModule.kt b/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/ExpoBlueskyGifViewModule.kt index 625e1d45f..b0b3e8eeb 100644 --- a/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/ExpoBlueskyGifViewModule.kt +++ b/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/ExpoBlueskyGifViewModule.kt @@ -6,49 +6,50 @@ import expo.modules.kotlin.modules.Module import expo.modules.kotlin.modules.ModuleDefinition class ExpoBlueskyGifViewModule : Module() { - override fun definition() = ModuleDefinition { - Name("ExpoBlueskyGifView") - - AsyncFunction("prefetchAsync") { sources: List<String> -> - val activity = appContext.currentActivity ?: return@AsyncFunction - val glide = Glide.with(activity) - - sources.forEach { source -> - glide - .download(source) - .diskCacheStrategy(DiskCacheStrategy.DATA) - .submit() + override fun definition() = + ModuleDefinition { + Name("ExpoBlueskyGifView") + + AsyncFunction("prefetchAsync") { sources: List<String> -> + val activity = appContext.currentActivity ?: return@AsyncFunction + val glide = Glide.with(activity) + + sources.forEach { source -> + glide + .download(source) + .diskCacheStrategy(DiskCacheStrategy.DATA) + .submit() + } } - } - View(GifView::class) { - Events( - "onPlayerStateChange" - ) + View(GifView::class) { + Events( + "onPlayerStateChange", + ) - Prop("source") { view: GifView, source: String -> - view.source = source - } + Prop("source") { view: GifView, source: String -> + view.source = source + } - Prop("placeholderSource") { view: GifView, source: String -> - view.placeholderSource = source - } + Prop("placeholderSource") { view: GifView, source: String -> + view.placeholderSource = source + } - Prop("autoplay") { view: GifView, autoplay: Boolean -> - view.autoplay = autoplay - } + Prop("autoplay") { view: GifView, autoplay: Boolean -> + view.autoplay = autoplay + } - AsyncFunction("playAsync") { view: GifView -> - view.play() - } + AsyncFunction("playAsync") { view: GifView -> + view.play() + } - AsyncFunction("pauseAsync") { view: GifView -> - view.pause() - } + AsyncFunction("pauseAsync") { view: GifView -> + view.pause() + } - AsyncFunction("toggleAsync") { view: GifView -> - view.toggle() + AsyncFunction("toggleAsync") { view: GifView -> + view.toggle() + } } } - } } diff --git a/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/GifView.kt b/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/GifView.kt index be5830df7..5e467a160 100644 --- a/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/GifView.kt +++ b/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/GifView.kt @@ -1,6 +1,5 @@ package expo.modules.blueskygifview - import android.content.Context import android.graphics.Color import android.graphics.drawable.Animatable @@ -15,7 +14,10 @@ import expo.modules.kotlin.exception.Exceptions import expo.modules.kotlin.viewevent.EventDispatcher import expo.modules.kotlin.views.ExpoView -class GifView(context: Context, appContext: AppContext) : ExpoView(context, appContext) { +class GifView( + context: Context, + appContext: AppContext, +) : ExpoView(context, appContext) { // Events private val onPlayerStateChange by EventDispatcher() @@ -44,8 +46,7 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC } } - - //<editor-fold desc="Lifecycle"> + // <editor-fold desc="Lifecycle"> init { this.setBackgroundColor(Color.TRANSPARENT) @@ -70,80 +71,82 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC super.onDetachedFromWindow() } - //</editor-fold> + // </editor-fold> - //<editor-fold desc="Loading"> + // <editor-fold desc="Loading"> private fun load() { if (placeholderSource == null || source == null) { return } - this.webpRequest = glide.load(source) - .diskCacheStrategy(DiskCacheStrategy.DATA) - .skipMemoryCache(false) - .listener(object: RequestListener<Drawable> { - override fun onResourceReady( - resource: Drawable?, - model: Any?, - target: Target<Drawable>?, - dataSource: com.bumptech.glide.load.DataSource?, - isFirstResource: Boolean - ): Boolean { - if (placeholderRequest != null) { - glide.clear(placeholderRequest) - } - return false - } - - override fun onLoadFailed( - e: GlideException?, - model: Any?, - target: Target<Drawable>?, - isFirstResource: Boolean - ): Boolean { - return true - } - }) - .into(this.imageView) - - if (this.imageView.drawable == null || this.imageView.drawable !is Animatable) { - this.placeholderRequest = glide.load(placeholderSource) + this.webpRequest = + glide + .load(source) .diskCacheStrategy(DiskCacheStrategy.DATA) - // Let's not bloat the memory cache with placeholders - .skipMemoryCache(true) - .listener(object: RequestListener<Drawable> { - override fun onResourceReady( - resource: Drawable?, - model: Any?, - target: Target<Drawable>?, - dataSource: com.bumptech.glide.load.DataSource?, - isFirstResource: Boolean - ): Boolean { - // Incase this request finishes after the webp, let's just not set - // the drawable. This shouldn't happen because the request should get cancelled - if (imageView.drawable == null) { - imageView.setImageDrawable(resource) + .skipMemoryCache(false) + .listener( + object : RequestListener<Drawable> { + override fun onResourceReady( + resource: Drawable?, + model: Any?, + target: Target<Drawable>?, + dataSource: com.bumptech.glide.load.DataSource?, + isFirstResource: Boolean, + ): Boolean { + if (placeholderRequest != null) { + glide.clear(placeholderRequest) + } + return false } - return true - } - - override fun onLoadFailed( - e: GlideException?, - model: Any?, - target: Target<Drawable>?, - isFirstResource: Boolean - ): Boolean { - return true - } - }) - .submit() + + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: Target<Drawable>?, + isFirstResource: Boolean, + ): Boolean = true + }, + ).into(this.imageView) + + if (this.imageView.drawable == null || this.imageView.drawable !is Animatable) { + this.placeholderRequest = + glide + .load(placeholderSource) + .diskCacheStrategy(DiskCacheStrategy.DATA) + // Let's not bloat the memory cache with placeholders + .skipMemoryCache(true) + .listener( + object : RequestListener<Drawable> { + override fun onResourceReady( + resource: Drawable?, + model: Any?, + target: Target<Drawable>?, + dataSource: com.bumptech.glide.load.DataSource?, + isFirstResource: Boolean, + ): Boolean { + // Incase this request finishes after the webp, let's just not set + // the drawable. This shouldn't happen because the request should get cancelled + if (imageView.drawable == null) { + imageView.setImageDrawable(resource) + } + return true + } + + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: Target<Drawable>?, + isFirstResource: Boolean, + ): Boolean = true + }, + ).submit() } } - //</editor-fold> + // </editor-fold> - //<editor-fold desc="Controls"> + // <editor-fold desc="Controls"> fun play() { this.imageView.play() @@ -165,16 +168,18 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC } } - //</editor-fold> + // </editor-fold> - //<editor-fold desc="Util"> + // <editor-fold desc="Util"> fun firePlayerStateChange() { - onPlayerStateChange(mapOf( - "isPlaying" to this.isPlaying, - "isLoaded" to this.isLoaded, - )) + onPlayerStateChange( + mapOf( + "isPlaying" to this.isPlaying, + "isLoaded" to this.isLoaded, + ), + ) } - //</editor-fold> + // </editor-fold> } diff --git a/modules/expo-bluesky-gif-view/ios/ExpoBlueskyGifViewModule.swift b/modules/expo-bluesky-gif-view/ios/ExpoBlueskyGifViewModule.swift index 7c7132290..9156bd199 100644 --- a/modules/expo-bluesky-gif-view/ios/ExpoBlueskyGifViewModule.swift +++ b/modules/expo-bluesky-gif-view/ios/ExpoBlueskyGifViewModule.swift @@ -5,11 +5,11 @@ import SDWebImageWebPCoder public class ExpoBlueskyGifViewModule: Module { public func definition() -> ModuleDefinition { Name("ExpoBlueskyGifView") - + OnCreate { SDImageCodersManager.shared.addCoder(SDImageGIFCoder.shared) } - + AsyncFunction("prefetchAsync") { (sources: [URL]) in SDWebImagePrefetcher.shared.prefetchURLs(sources, context: Util.createContext(), progress: nil) } @@ -18,27 +18,27 @@ public class ExpoBlueskyGifViewModule: Module { Events( "onPlayerStateChange" ) - + Prop("source") { (view: GifView, prop: String) in view.source = prop } - + Prop("placeholderSource") { (view: GifView, prop: String) in view.placeholderSource = prop } - + Prop("autoplay") { (view: GifView, prop: Bool) in view.autoplay = prop } - + AsyncFunction("toggleAsync") { (view: GifView) in view.toggle() } - + AsyncFunction("playAsync") { (view: GifView) in view.play() } - + AsyncFunction("pauseAsync") { (view: GifView) in view.pause() } diff --git a/modules/expo-bluesky-gif-view/ios/GifView.swift b/modules/expo-bluesky-gif-view/ios/GifView.swift index de722d7a6..b42a4735c 100644 --- a/modules/expo-bluesky-gif-view/ios/GifView.swift +++ b/modules/expo-bluesky-gif-view/ios/GifView.swift @@ -16,14 +16,14 @@ public class GifView: ExpoView, AVPlayerViewControllerDelegate { ) private var isPlaying = true private var isLoaded = false - + // Requests private var webpOperation: SDWebImageCombinedOperation? private var placeholderOperation: SDWebImageCombinedOperation? // Props - var source: String? = nil - var placeholderSource: String? = nil + var source: String? + var placeholderSource: String? var autoplay = true { didSet { if !autoplay { @@ -78,8 +78,7 @@ public class GifView: ExpoView, AVPlayerViewControllerDelegate { // See: // https://github.com/SDWebImage/SDWebImage/blob/master/Docs/HowToUse.md#using-asynchronous-image-caching-independently if !SDImageCache.shared.diskImageDataExists(withKey: source), - let url = URL(string: placeholderSource) - { + let url = URL(string: placeholderSource) { self.placeholderOperation = imageManager.loadImage( with: url, options: [.retryFailed], @@ -132,8 +131,7 @@ public class GifView: ExpoView, AVPlayerViewControllerDelegate { if let placeholderSource = self.placeholderSource, imageUrl?.absoluteString == placeholderSource, self.imageView.image == nil, - let image = image - { + let image = image { self.setImage(image) return } @@ -142,8 +140,7 @@ public class GifView: ExpoView, AVPlayerViewControllerDelegate { imageUrl?.absoluteString == source, // UIImage perf suckssss if the image is animated let data = data, - let animatedImage = SDAnimatedImage(data: data) - { + let animatedImage = SDAnimatedImage(data: data) { self.placeholderOperation?.cancel() self.isPlaying = self.autoplay self.isLoaded = true |