using Newtonsoft.Json.Linq; using ReactNative.Bridge; using ReactNative.UIManager; using System; using System.IO; using System.Collections.Generic; namespace RNViewShot { /// /// A module that allows JS to share data. /// class RNViewShotModule : ReactContextNativeModuleBase { private const string ErrorUnableToSnapshot = "E_UNABLE_TO_SNAPSHOT"; private readonly ReactContext _reactContext; /// /// Instantiates the . /// public RNViewShotModule(ReactContext reactContext) : base(reactContext) { this._reactContext = reactContext; } /// /// The name of the native module. /// public override string Name { get { return "RNViewShot"; } } [ReactMethod] public void releaseCapture (string uri) { // TODO implement me } [ReactMethod] public void captureRef(int tag, JObject options, IPromise promise) { string format = options["format"] != null ? options.Value("format") : "png"; double quality = options["quality"] != null ? options.Value("quality") : 1.0; int? width = options["width"] != null ? options.Value("width") : null; int? height = options["height"] != null ? options.Value("height") : null; string result = options["result"] != null ? options.Value("result") : "file"; string path = options["path"] != null ? options.Value("path") : null; if (format != "png" && format != "jpg" && format != "jpeg") { promise.Reject(ViewShot.ErrorUnableToSnapshot, "Unsupported image format: " + format + ". Try one of: png | jpg | jpeg"); return; } UIManagerModule uiManager = this._reactContext.GetNativeModule(); var viewShot = new ViewShot(tag, format, quality, width, height, path, result, promise); uiManager.AddUIBlock(viewShot); } } }