コード例 #1
0
        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
                });
            }
        }
コード例 #2
0
        public void DispatchEvent <T>(FrameworkElement view, string eventName, T arg)
        {
            var argWriter = arg as JSValueArgWriter;

            if (argWriter != null)
            {
                XamlUIService.FromContext(Handle).DispatchEvent(view, eventName, argWriter);
            }
            else
            {
                XamlUIService.FromContext(Handle).DispatchEvent(view, eventName, (IJSValueWriter writer) => writer.WriteValue(arg));
            }
        }