/// <summary> /// Registers a new root view. /// </summary> /// <param name="rootView">The root view instance.</param> /// <returns>The root view tag.</returns> /// <remarks> /// JavaScript can use the returned tag with to add or remove children /// to this view through <see cref="manageChildren(int, int[], int[], int[], int[], int[])"/>. /// </remarks> public int AddMeasuredRootView(SizeMonitoringCanvas rootView) { var tag = _nextRootTag; _nextRootTag += RootViewTagIncrement; var width = rootView.ActualWidth; var height = rootView.ActualHeight; var context = new ThemedReactContext(Context); _uiImplementation.RegisterRootView(rootView, tag, width, height, context); var resizeCount = 0; rootView.SetOnSizeChangedListener((sender, args) => { var currentCount = ++resizeCount; var newWidth = args.NewSize.Width; var newHeight = args.NewSize.Height; Context.RunOnNativeModulesQueueThread(() => { if (currentCount == resizeCount) { Context.AssertOnNativeModulesQueueThread(); _uiImplementation.UpdateRootNodeSize(tag, newWidth, newHeight); } }); }); return(tag); }
/// <summary> /// Registers a new root view. /// </summary> /// <param name="rootView">The root view instance.</param> /// <returns>The root view tag.</returns> /// <remarks> /// JavaScript can use the returned tag with to add or remove children /// to this view through <see cref="manageChildren(int, int[], int[], int[], int[], int[])"/>. /// </remarks> public async Task <int> AddMeasuredRootViewAsync(ReactRootView rootView) { // Called on main dispatcher thread DispatcherHelpers.AssertOnDispatcher(); var tag = _nextRootTag; _nextRootTag += RootViewTagIncrement; // Set tag early in case of concurrent DetachRootViewAsync rootView.SetTag(tag); var context = new ThemedReactContext(Context); await DispatcherHelpers.CallOnDispatcher(rootView.Dispatcher, () => { var width = rootView.ActualWidth; var height = rootView.ActualHeight; _layoutActionQueue.Dispatch(() => { _uiImplementation.RegisterRootView(rootView, tag, width, height, context); }); var resizeCount = 0; rootView.SetOnSizeChangedListener((sender, args) => { var currentCount = ++resizeCount; var newWidth = args.NewSize.Width; var newHeight = args.NewSize.Height; _layoutActionQueue.Dispatch(() => { if (currentCount == resizeCount) { _layoutActionQueue.AssertOnThread(); _uiImplementation.UpdateRootNodeSize(tag, newWidth, newHeight); } }); }); rootView.StartTouchHandling(); #if WINDOWS_UWP // Register view in DeviceInfoModule for tracking its dimensions Context.GetNativeModule <DeviceInfoModule>().RegisterRootView(rootView, tag); #endif return(true); }, true); // Allow inlining return(tag); }
/// <summary> /// Registers a new root view. /// </summary> /// <param name="rootView">The root view instance.</param> /// <returns>The root view tag.</returns> /// <remarks> /// JavaScript can use the returned tag with to add or remove children /// to this view through <see cref="manageChildren(int, int[], int[], int[], int[], int[])"/>. /// </remarks> public int AddMeasuredRootView(ReactRootView rootView) { // Called on main dispatcher thread DispatcherHelpers.AssertOnDispatcher(); var tag = _nextRootTag; _nextRootTag += RootViewTagIncrement; var context = new ThemedReactContext(Context); DispatcherHelpers.RunOnDispatcher(rootView.Dispatcher, () => { var width = rootView.ActualWidth; var height = rootView.ActualHeight; _layoutActionQueue.Dispatch(() => { _uiImplementation.RegisterRootView(rootView, tag, width, height, context); }); var resizeCount = 0; rootView.SetOnSizeChangedListener((sender, args) => { var currentCount = ++resizeCount; var newWidth = args.NewSize.Width; var newHeight = args.NewSize.Height; _layoutActionQueue.Dispatch(() => { if (currentCount == resizeCount) { _layoutActionQueue.AssertOnThread(); _uiImplementation.UpdateRootNodeSize(tag, newWidth, newHeight); } }); }); }, true); // Allow inlining return(tag); }
/// <summary> /// Registers a new root view. /// </summary> /// <param name="rootView">The root view instance.</param> /// <returns>The root view tag.</returns> /// <remarks> /// JavaScript can use the returned tag with to add or remove children /// to this view through <see cref="manageChildren(int, int[], int[], int[], int[], int[])"/>. /// </remarks> public int AddMeasuredRootView(SizeMonitoringCanvas rootView) { var tag = _nextRootTag; _nextRootTag += RootViewTagIncrement; //var width = rootView.ActualWidth; //var height = rootView.ActualHeight; var geometry = rootView.Geometry; var width = geometry.Width; var height = geometry.Height; RNTracer.Write(Common.ReactConstants.Tag, "RootView : " + width + " * " + height); var context = new ThemedReactContext(Context); _uiImplementation.RegisterRootView(rootView, tag, width, height, context); var resizeCount = 0; rootView.SetOnSizeChangedListener((sender, args) => { var currentCount = ++resizeCount; /* * var newWidth = args.NewSize.Width; * var newHeight = args.NewSize.Height; * * Context.RunOnNativeModulesQueueThread(() => * { * if (currentCount == resizeCount) * { * Context.AssertOnNativeModulesQueueThread(); * _uiImplementation.UpdateRootNodeSize(tag, newWidth, newHeight, _eventDispatcher); * } * }); */ }); return(tag); }