public async void captureRef(int tag, JSValue options, IReactPromise <string> promise) { string format = options["format"].IsNull ? "png" : options["format"].AsString(); double quality = options["quality"].IsNull ? 1.0 : options["quality"].AsDouble(); int width = options["width"].IsNull ? 0 : options["width"].AsInt16(); int height = options["height"].IsNull ? 0 : options["height"].AsInt16(); string result = options["result"].IsNull ? "tmpfile" : options["result"].AsString(); string path = options["path"].IsNull ? null : options["path"].AsString(); if (format != "png" && format != "jpg" && format != "jpeg") { promise.Reject(new ReactError { Code = ViewShot.ErrorUnableToSnapshot, Message = "Unsupported image format: " + format + ". Try one of: png | jpg | jpeg" }); return; } try { var control = XamlUIService.FromContext(_context.Handle).ElementFromReactTag(tag) as FrameworkElement; ViewShot view = new ViewShot(); var output = await view.Execute(control, format, quality, width, height, path, result); promise.Resolve(output); } catch (Exception exc) { promise.Reject(new ReactError { Message = exc.Message, Exception = exc }); } }
public void captureRef(int tag, JObject options, IPromise promise) { string format = options["format"] != null?options.Value <string>("format") : "png"; double quality = options["quality"] != null?options.Value <double>("quality") : 1.0; int?width = options["width"] != null?options.Value <int?>("width") : null; int?height = options["height"] != null?options.Value <int?>("height") : null; string result = options["result"] != null?options.Value <string>("result") : "file"; string path = options["path"] != null?options.Value <string>("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 <UIManagerModule>(); var viewShot = new ViewShot(tag, format, quality, width, height, path, result, promise); uiManager.AddUIBlock(viewShot); }