From 173430fb7455964fe11f00e92ae348d8b25f1c2c Mon Sep 17 00:00:00 2001 From: "Alexandre.Gagnon" <3418768+a-gagnon@users.noreply.github.com> Date: Thu, 21 Sep 2023 15:24:30 -0400 Subject: [PATCH] Task/expose user preferences options (#302) * Expose userPreferences from the IModelAppOptions * rush change. --------- Co-authored-by: Arun George <11051042+aruniverse@users.noreply.github.com> --- ...rPreferences-options_2023-09-21-18-01.json | 10 ++++++++ .../src/services/BaseInitializer.ts | 23 ++++++++++++------- packages/modules/viewer-react/src/types.ts | 6 +++-- 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 common/changes/@itwin/viewer-react/task-expose-userPreferences-options_2023-09-21-18-01.json diff --git a/common/changes/@itwin/viewer-react/task-expose-userPreferences-options_2023-09-21-18-01.json b/common/changes/@itwin/viewer-react/task-expose-userPreferences-options_2023-09-21-18-01.json new file mode 100644 index 00000000..37442b44 --- /dev/null +++ b/common/changes/@itwin/viewer-react/task-expose-userPreferences-options_2023-09-21-18-01.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@itwin/viewer-react", + "comment": "Expose the userPreferences initialization option from IModelApp.", + "type": "minor" + } + ], + "packageName": "@itwin/viewer-react" +} \ No newline at end of file diff --git a/packages/modules/viewer-react/src/services/BaseInitializer.ts b/packages/modules/viewer-react/src/services/BaseInitializer.ts index 6479c30c..f0ea1760 100644 --- a/packages/modules/viewer-react/src/services/BaseInitializer.ts +++ b/packages/modules/viewer-react/src/services/BaseInitializer.ts @@ -3,6 +3,7 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ +import type { UiSyncEventArgs } from "@itwin/appui-abstract"; import { AppNotificationManager, FrameworkAccuDraw, @@ -21,14 +22,17 @@ import { ITwinLocalization } from "@itwin/core-i18n"; import { UiCore } from "@itwin/core-react"; import { FrontendIModelsAccess } from "@itwin/imodels-access-frontend"; import { IModelsClient } from "@itwin/imodels-client-management"; -import { ISelectionProvider, Presentation, SelectionChangeEventArgs } from "@itwin/presentation-frontend"; +import { getInstancesCount } from "@itwin/presentation-common"; +import type { + ISelectionProvider, + SelectionChangeEventArgs, +} from "@itwin/presentation-frontend"; +import { Presentation } from "@itwin/presentation-frontend"; import { RealityDataAccessClient } from "@itwin/reality-data-client"; import { ViewerPerformance } from "../services/telemetry"; import type { ViewerInitializerParams } from "../types"; import { makeCancellable } from "../utilities/MakeCancellable"; -import { UiSyncEventArgs } from "@itwin/appui-abstract"; -import { getInstancesCount } from "@itwin/presentation-common"; const syncSelectionCount = () => { Presentation.selection.selectionChange.addListener( @@ -62,15 +66,17 @@ const syncSelectionCount = () => { // This preserves how the active selection scope was synced between Presentation and AppUi before its removal in 4.x const syncActiveSelectionScope = () => { - // If the user doesn't set any active scope and uses the default scope, then the Presentation active scope would be undefined. + // If the user doesn't set any active scope and uses the default scope, then the Presentation active scope would be undefined. // Thus, we have to sync it for the first time here. - Presentation.selection.scopes.activeScope = UiFramework.getActiveSelectionScope(); - + Presentation.selection.scopes.activeScope = + UiFramework.getActiveSelectionScope(); + SyncUiEventDispatcher.onSyncUiEvent.addListener((args: UiSyncEventArgs) => { if (args.eventIds.has(SessionStateActionId.SetSelectionScope)) { // After 4.x the AppUI no longer has a presentation dep and therefore we have the responsibility of // syncing the Presentation.selection.scopes.activeScope with the AppUi's UiSyncEvent for SetSelectionScope - Presentation.selection.scopes.activeScope = UiFramework.getActiveSelectionScope(); + Presentation.selection.scopes.activeScope = + UiFramework.getActiveSelectionScope(); } }); }; @@ -273,6 +279,7 @@ export const getIModelAppOptions = ( toolAdmin: options?.toolAdmin, renderSys: options?.renderSys, realityDataAccess, + userPreferences: options?.userPreferences, }; }; @@ -304,4 +311,4 @@ class ViewerAccuSnap extends AccuSnap { } return snaps; } -} \ No newline at end of file +} diff --git a/packages/modules/viewer-react/src/types.ts b/packages/modules/viewer-react/src/types.ts index 37356201..ad2b9ced 100644 --- a/packages/modules/viewer-react/src/types.ts +++ b/packages/modules/viewer-react/src/types.ts @@ -89,9 +89,9 @@ export interface LoaderProps { | ((iModel: IModelConnection) => Promise); /** additional frontstages to register */ frontstages?: ViewerFrontstage[]; - /** menu items for the backstage + /** menu items for the backstage * @deprecated in 4.x. Use [UiItemsProvider.provideBackstageItems](https://www.itwinjs.org/reference/appui-react/uiprovider/uiitemsprovider/). - */ + */ backstageItems?: ViewerBackstageItem[]; /** additional viewport options for the default frontstage's viewport control */ viewportOptions?: ViewerViewportControlOptions; @@ -116,6 +116,7 @@ export type ViewerIModelAppOptions = Pick< | "toolAdmin" | "renderSys" | "realityDataAccess" + | "userPreferences" >; export interface ViewerInitializerParams extends ViewerIModelAppOptions { @@ -190,6 +191,7 @@ const iTwinViewerInitializerParamSample: OptionalToUndefinedUnion