about summary refs log tree commit diff
path: root/modules/expo-bluesky-gif-view/ios/ExpoBlueskyGifViewModule.swift
blob: 7c7132290de4d0ed83e717ea2dc1da098f94e7cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import ExpoModulesCore
import SDWebImage
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)
    }

    View(GifView.self) {
      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()
      }
    }
  }
}