/// <summary> /// Detaches a root view from the size monitoring hooks in preparation for the unmount /// </summary> /// <param name="rootView">The root view instance.</param> public void DetachRootView(ReactRootView rootView) { // Called on main dispatcher thread DispatcherHelpers.AssertOnDispatcher(); DispatcherHelpers.RunOnDispatcher(rootView.Dispatcher, () => rootView.RemoveSizeChanged(), true); // allow inlining }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (Build.VERSION.SdkInt >= BuildVersionCodes.M) { if (!Settings.CanDrawOverlays(this)) { Intent intent = new Intent(Settings.ActionManageOverlayPermission, Uri.Parse("package:" + PackageName)); StartActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); } } mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.Builder() .SetApplication(Application) .SetBundleAssetName("index.android.bundle") .SetJSMainModulePath("index") .AddPackage(new MainReactPackage()) #if DEBUG .SetUseDeveloperSupport(true) #else .SetUseDeveloperSupport(false) #endif .SetInitialLifecycleState(LifecycleState.Resumed) .Build(); mReactRootView.StartReactApplication(mReactInstanceManager, "MyReactNativeApp", null); SetContentView(mReactRootView); }
public async Task ReactRootView_SecondaryWindowStress() { var jsBundleFile = "ms-appx:///Resources/mwtest.js"; ReactInstanceManager manager = null; await DispatcherHelpers.CallOnDispatcherAsync(() => manager = CreateReactInstanceManager(jsBundleFile)); var reactContext = await DispatcherHelpers.CallOnDispatcherAsync( () => manager.CreateReactContextAsync(CancellationToken.None)); int currentDelay = 2000; for (int i = 0; i < 30; i++) { currentDelay /= 2; // Create a window var dispatcher = await CreateView(() => { var rv = new ReactRootView(); rv.StartReactApplication( manager, "alt_window", null); return(rv); }); await Task.Delay(currentDelay); await CloseView(manager, dispatcher); } await DispatcherHelpers.CallOnDispatcherAsync(async() => await DisposeInstanceManager(manager)); }
public DeviceViewInfo(ApplicationView applicationView, ReactRootView rootView, DisplayInformation displayInformation, int tag) { this.ApplicationView = applicationView; this.RootView = rootView; this.DisplayInformation = displayInformation; this.RootViewTag = tag; this.RootViewId = rootView.InitialProps?.GetValue("reactxp_rootViewId")?.ToString(); this.CurrentDisplayMetrics = DisplayMetrics.GetForDeviceView(this); }
/// <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> /// Unregister <paramref name="rootView"/> and stop keeping track of his dimensions /// </summary> /// <param name="rootView">The react root view</param> public void UnregisterRootView(ReactRootView rootView) { DispatcherHelpers.AssertOnDispatcher(rootView); var info = _registeredViews.Values.SingleOrDefault(i => i.RootView == rootView); if (info != null && _registeredViews.TryRemove(info.ApplicationView, out info)) { info.ApplicationView.VisibleBoundsChanged -= OnVisibleBoundsChanged; info.DisplayInformation.OrientationChanged -= OnOrientationChanged; } }
protected override void OnLaunched(LaunchActivatedEventArgs args) { base.OnLaunched(args); var rootView = Window.Current.Content as ReactRootView; if (rootView == null) { rootView = new ReactRootView(); rootView.ReactNativeHost = this.Host; rootView.ComponentName = "example"; Window.Current.Content = rootView; } Window.Current.Activate(); }
/// <summary> /// Detaches a root view from the size monitoring hooks in preparation for the unmount /// </summary> /// <param name="rootView">The root view instance.</param> /// <returns>A task to await the cleanup of the root view.</returns> public async Task <Task> DetachRootViewAsync(ReactRootView rootView) { // Called on main dispatcher thread DispatcherHelpers.AssertOnDispatcher(); await DispatcherHelpers.CallOnDispatcher(rootView.Dispatcher, () => { rootView.RemoveSizeChanged(); return(true); }, true); // allow inlining var rootTag = rootView.GetTag(); var taskCompletionSource = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _rootViewCleanupTasks.AddOrUpdate(rootTag, taskCompletionSource, (k, v) => throw new InvalidOperationException("Duplicate root view removal")); return(taskCompletionSource.Task); }
private void InitializeReactNative() { ViewManagerTestHooks.Enabled = true; ViewManagerTestHooks.ViewCreatedTestHook = (view) => { if (view is Border) { view.Loaded += View_Loaded; } }; _host.OnResume(null); _host.ApplyArguments(null); ReactRootView root = _host.OnCreate(JObject.Parse("{ \"messageCount\": \"" + App.TotalMessages + "\" }")); this.Content = root; }
/// <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); }
private void startReactNative() { mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.Builder() .SetApplication(Application) .SetBundleAssetName("index.android.bundle") .SetJSMainModulePath("index") .AddPackage(new MainReactPackage()) #if DEBUG .SetUseDeveloperSupport(true) #else .SetUseDeveloperSupport(false) #endif .SetInitialLifecycleState(LifecycleState.Resumed) .Build(); mReactRootView.StartReactApplication(mReactInstanceManager, "MyReactNativeApp", null); SetContentView(mReactRootView); }
/// <summary> /// Detaches a root view from the size monitoring hooks in preparation for the unmount /// </summary> /// <param name="rootView">The root view instance.</param> /// <returns>A task to await the cleanup of the root view.</returns> public async Task <Task> DetachRootViewAsync(ReactRootView rootView) { // Called on main dispatcher thread DispatcherHelpers.AssertOnDispatcher(); await DispatcherHelpers.CallOnDispatcher(rootView.Dispatcher, () => { rootView.RemoveSizeChanged(); rootView.StopTouchHandling(); #if WINDOWS_UWP // Unregister view from DeviceInfoModule Context.GetNativeModule <DeviceInfoModule>().UnregisterRootView(rootView); #endif return(true); }, true); // allow inlining var rootTag = rootView.GetTag(); var taskCompletionSource = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _rootViewCleanupTasks.AddOrUpdate(rootTag, taskCompletionSource, (k, v) => throw new InvalidOperationException("Duplicate root view removal")); return(taskCompletionSource.Task); }
public static void OnCreate(this ReactRootView rootView, ReactNativeHost host) { // TODO: add global keyboard shortcuts }