Ei kuvausta

RNViewShotModule.cs 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Newtonsoft.Json.Linq;
  2. using ReactNative.Bridge;
  3. using ReactNative.UIManager;
  4. using System;
  5. using System.IO;
  6. using System.Collections.Generic;
  7. namespace RNViewShot
  8. {
  9. /// <summary>
  10. /// A module that allows JS to share data.
  11. /// </summary>
  12. class RNViewShotModule : ReactContextNativeModuleBase
  13. {
  14. private const string ErrorUnableToSnapshot = "E_UNABLE_TO_SNAPSHOT";
  15. private readonly ReactContext _reactContext;
  16. /// <summary>
  17. /// Instantiates the <see cref="RNViewShotModule"/>.
  18. /// </summary>
  19. public RNViewShotModule(ReactContext reactContext) : base(reactContext)
  20. {
  21. this._reactContext = reactContext;
  22. }
  23. /// <summary>
  24. /// The name of the native module.
  25. /// </summary>
  26. public override string Name
  27. {
  28. get
  29. {
  30. return "RNViewShot";
  31. }
  32. }
  33. [ReactMethod]
  34. public void takeSnapshot(int tag, JObject options, IPromise promise)
  35. {
  36. string format = options["format"] != null ? options.Value<string>("format") : "png";
  37. double quality = options["quality"] != null ? options.Value<double>("quality") : 1.0;
  38. int? width = options["width"] != null ? options.Value<int?>("width") : null;
  39. int? height = options["height"] != null ? options.Value<int?>("height") : null;
  40. string result = options["result"] != null ? options.Value<string>("result") : "file";
  41. UIManagerModule uiManager = this._reactContext.GetNativeModule<UIManagerModule>();
  42. uiManager.AddUIBlock(new ViewShot(tag, format, quality, width, height, result, promise));
  43. }
  44. }
  45. }