Skip to content

Commit

Permalink
Task/expose user preferences options (#302)
Browse files Browse the repository at this point in the history
* Expose userPreferences from the IModelAppOptions

* rush change.

---------

Co-authored-by: Arun George <11051042+aruniverse@users.noreply.github.com>
  • Loading branch information
a-gagnon and aruniverse authored Sep 21, 2023
1 parent f1ab635 commit 173430f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/viewer-react",
"comment": "Expose the userPreferences initialization option from IModelApp.",
"type": "minor"
}
],
"packageName": "@itwin/viewer-react"
}
23 changes: 15 additions & 8 deletions packages/modules/viewer-react/src/services/BaseInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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();
}
});
};
Expand Down Expand Up @@ -273,6 +279,7 @@ export const getIModelAppOptions = (
toolAdmin: options?.toolAdmin,
renderSys: options?.renderSys,
realityDataAccess,
userPreferences: options?.userPreferences,
};
};

Expand Down Expand Up @@ -304,4 +311,4 @@ class ViewerAccuSnap extends AccuSnap {
}
return snaps;
}
}
}
6 changes: 4 additions & 2 deletions packages/modules/viewer-react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ export interface LoaderProps {
| ((iModel: IModelConnection) => Promise<void>);
/** 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;
Expand All @@ -116,6 +116,7 @@ export type ViewerIModelAppOptions = Pick<
| "toolAdmin"
| "renderSys"
| "realityDataAccess"
| "userPreferences"
>;

export interface ViewerInitializerParams extends ViewerIModelAppOptions {
Expand Down Expand Up @@ -190,6 +191,7 @@ const iTwinViewerInitializerParamSample: OptionalToUndefinedUnion<ViewerInitiali
onIModelAppInit: undefined,
additionalI18nNamespaces: undefined,
extensions: undefined,
userPreferences: undefined,
};

export const iTwinViewerInitializerParamList = Object.keys(
Expand Down

0 comments on commit 173430f

Please sign in to comment.