Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mobile-ui-react/ActionSheetButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import { CommonProps, IconSpec } from "@itwin/core-react";
import { IconSpec } from "@itwin/core-react";
import { ActionSheetProps, presentActionSheet } from "@itwin/mobile-sdk-core";
import { NavigationButton } from "./NavigationPanel";
import { CommonProps } from "./MobileUi";

/**
* Properties for {@link ActionSheetButton}
Expand Down
10 changes: 8 additions & 2 deletions src/mobile-ui-react/BottomPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
import * as React from "react";
import classnames from "classnames";
import { BeUiEvent } from "@itwin/core-bentley";
import { CommonProps, getCssVariableAsNumber } from "@itwin/core-react";
import { Optional } from "@itwin/mobile-sdk-core";
import { makeRefHandler, MutableHtmlDivRefOrFunction, useBeUiEvent, useWindowEvent } from "./MobileUi";
import {
CommonProps,
getCssVariableAsNumber,
makeRefHandler,
MutableHtmlDivRefOrFunction,
useBeUiEvent,
useWindowEvent,
} from "./MobileUi";
import { PanelHeader, PanelHeaderProps } from "./PanelHeader";
import { ResizablePanel, ResizablePanelProps } from "./ResizablePanel";
import "./BottomPanel.scss";
Expand Down
2 changes: 1 addition & 1 deletion src/mobile-ui-react/CenterDiv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import classnames from "classnames";
import { CommonProps } from "@itwin/core-react";
import "./CenterDiv.scss";
import { CommonProps } from "./MobileUi";

/**
* Properties for {@link CenterDiv} component
Expand Down
4 changes: 2 additions & 2 deletions src/mobile-ui-react/CountNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import classnames from "classnames";
import { CommonProps, IconSpec } from "@itwin/core-react";
import { IconSpec } from "@itwin/core-react";
import { AlertAction } from "@itwin/mobile-sdk-core";
import { ActionSheetButton } from "./ActionSheetButton";
import { IconImage } from "./IconImage";
import { MobileUi } from "./MobileUi";
import { CommonProps, MobileUi } from "./MobileUi";

import "./CountNotification.scss";

Expand Down
2 changes: 1 addition & 1 deletion src/mobile-ui-react/HorizontalPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import classnames from "classnames";
import { CommonProps } from "@itwin/core-react";
import { CommonProps } from "./MobileUi";

import "./HorizontalPicker.scss";

Expand Down
57 changes: 56 additions & 1 deletion src/mobile-ui-react/MobileUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,37 @@
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import { BackendError, Localization } from "@itwin/core-common";
import { getCssVariable, getCssVariableAsNumber } from "@itwin/core-react";
import { ColorTheme, SessionStateActionId, SyncUiEventDispatcher, SyncUiEventId, SYSTEM_PREFERRED_COLOR_THEME, UiFramework, UiSyncEventArgs } from "@itwin/appui-react";
import { EmphasizeElements, IModelApp, IModelConnection, ScreenViewport, SelectionSet, Tool, Viewport } from "@itwin/core-frontend";
import { BeEvent, BeUiEvent, BriefcaseStatus, Id64Set, Listener } from "@itwin/core-bentley";
import { getAllViewports, getEmphasizeElements, Messenger, MobileCore, UIError } from "@itwin/mobile-sdk-core";

import "./MobileUi.scss";

/** Props used by components that expect class name to be passed in.
*
* __Note__: Copied from @itwin/core-react, where it is being deprecated. It will **not ever** be
* deprecated from @itwin/mobile-ui-react.
* @public
*/
export interface ClassNameProps {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets review with the appui team why this was deprecated, and what they expected consumers to do, before we re-export a deprecated type from another repo as public here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to draft for now while we decide what to do and created a new PR to allow lint to pass.

/** Custom CSS class name */
className?: string;
}

/** Common props used by components.
*
* __Note__: Copied from @itwin/core-react, where it is being deprecated. It will **not ever** be
* deprecated from @itwin/mobile-ui-react.
* @public
*/
export interface CommonProps extends ClassNameProps {
/** Custom CSS style properties */
style?: React.CSSProperties;
/** Optional unique identifier for item. If defined it will be added to DOM Element attribute as data-item-id */
itemId?: string;
}

/** Type used for MobileUi.onClose BeEvent. */
export declare type CloseListener = () => void;

Expand Down Expand Up @@ -669,3 +692,35 @@ export function useActiveColorSchemeIsDark() {
}, [isMountedRef]), MobileUi.onColorSchemeChanged);
return isDark;
}

/** Get CSS variable
* @public
*
* __Note__: Copied from @itwin/core-react, where it is being deprecated. It will **not ever** be
* deprecated from @itwin/mobile-ui-react.
*/
export function getCssVariable(
variableName: string,
htmlElement?: HTMLElement,
): string {
const element = htmlElement ?? document.documentElement;
const cssStyles = getComputedStyle(element, null);
const cssVal = String(cssStyles.getPropertyValue(variableName)).trim();
return cssVal;
}

/** Get CSS variable as number
* @public
*
* __Note__: Copied from @itwin/core-react, where it is being deprecated. It will **not ever** be
* deprecated from @itwin/mobile-ui-react.
*/
export function getCssVariableAsNumber(
variableName: string,
htmlElement?: HTMLElement,
): number {
let cssValNum: number = NaN;
const cssValStr = getCssVariable(variableName, htmlElement);
if (cssValStr) cssValNum = parseFloat(cssValStr);
return cssValNum;
}
3 changes: 1 addition & 2 deletions src/mobile-ui-react/ModalEntryFormDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import classnames from "classnames";
import { CommonProps } from "@itwin/core-react";
import { UiFramework } from "@itwin/appui-react";
import { getCssVariableAsNumberOrDefault, MobileCore, Optional } from "@itwin/mobile-sdk-core";
import { CloseButton } from "./NavigationPanel";
import { MobileUi } from "./MobileUi";
import { CommonProps, MobileUi } from "./MobileUi";

import "./ModalEntryFormDialog.scss";

Expand Down
4 changes: 2 additions & 2 deletions src/mobile-ui-react/NavigationPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import classnames from "classnames";
import { ClassNameProps, CommonProps, IconSpec } from "@itwin/core-react";
import { IconSpec } from "@itwin/core-react";
import { ConditionalBooleanValue, ConditionalStringValue } from "@itwin/appui-abstract";
import { IconImage } from "./IconImage";
import { useSyncUiEvent } from "./MobileUi";
import { ClassNameProps, CommonProps, useSyncUiEvent } from "./MobileUi";
import "./NavigationPanel.scss";

import {
Expand Down
2 changes: 1 addition & 1 deletion src/mobile-ui-react/PanelHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import classnames from "classnames";
import { CommonProps } from "@itwin/core-react";
import { withoutClassName } from "@itwin/mobile-sdk-core";
import { DraggableComponent, DraggableComponentCallbackProps } from "./ResizablePanel";
import { CommonProps } from "./MobileUi";

import "./PanelHeader.scss";

Expand Down
3 changes: 1 addition & 2 deletions src/mobile-ui-react/ResizablePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import * as React from "react";
import classnames from "classnames";
import { Point2d, XAndY } from "@itwin/core-geometry";
import { CommonProps, getCssVariableAsNumber } from "@itwin/core-react";
import { ReloadedEvent } from "@itwin/mobile-sdk-core";
import { ReactUseState, useIsMountedRef, useWindowEvent } from "./MobileUi";
import { CommonProps, getCssVariableAsNumber, ReactUseState, useIsMountedRef, useWindowEvent } from "./MobileUi";
import "./ResizablePanel.scss";

/**
Expand Down
3 changes: 1 addition & 2 deletions src/mobile-ui-react/ScrollableWithFades.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import * as React from "react";
import classnames from "classnames";
import { ColorDef } from "@itwin/core-common";
import { ClassNameProps, getCssVariable } from "@itwin/core-react";
import { useScroll, useWindowEvent } from "./MobileUi";
import { ClassNameProps, getCssVariable, useScroll, useWindowEvent } from "./MobileUi";

import "./ScrollableWithFades.scss";

Expand Down
4 changes: 2 additions & 2 deletions src/mobile-ui-react/Suggestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import * as React from "react";
import classnames from "classnames";
import { BeUiEvent } from "@itwin/core-bentley";
import { getCssVariableAsNumber, useOnOutsideClick } from "@itwin/core-react";
import { ToolAssistanceInstructions } from "@itwin/core-frontend";
import { IconImage } from "./IconImage";
import { useBeUiEvent } from "./MobileUi";
import { getCssVariableAsNumber, useBeUiEvent } from "./MobileUi";
import { useOnOutsideClick } from "./useOnOutsideClick";
import "./Suggestion.scss";

/**
Expand Down
3 changes: 1 addition & 2 deletions src/mobile-ui-react/TabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import classnames from "classnames";
import { getCssVariable, getCssVariableAsNumber } from "@itwin/core-react";
import { ColorDef } from "@itwin/core-common";
import { BottomPanelProps } from "./BottomPanel";
import { HorizontalScrollableWithFades } from "./ScrollableWithFades";
import { useHorizontalScrollChildVisibleOnResize } from "./MobileUi";
import { getCssVariable, getCssVariableAsNumber, useHorizontalScrollChildVisibleOnResize } from "./MobileUi";

import "./TabBar.scss";

Expand Down
3 changes: 1 addition & 2 deletions src/mobile-ui-react/TileGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import classnames from "classnames";
import { CommonProps } from "@itwin/core-react";
import { useMediaQuery, useScrolling } from "./MobileUi";
import { CommonProps, useMediaQuery, useScrolling } from "./MobileUi";
import "./TileGrid.scss";

/**
Expand Down
79 changes: 79 additions & 0 deletions src/mobile-ui-react/Timer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

/*
* NOTE: This entire file was copied from @itwin/core-react, where it is being deprecated. It was
* then modified to make things internal instead of public and deprecated.
*/

/** Signature for [[Timer]] execute callback.
* @internal
*/
export type ExecuteHandler = (this: void) => void;

/** Notifies handler after a set interval.
* @internal
*/
export class Timer {
private _delay: number;
private _isRunning = false;
private _timerId = 0;
private _onExecute: ExecuteHandler | undefined;

/**
* Creates a new Timer.
* @param msDelay Time interval in milliseconds after which handler will be notified.
*/
public constructor(msDelay: number) {
this._delay = msDelay;
}

/** Indicates whether the timer is running */
public get isRunning(): boolean {
return this._isRunning;
}

/** Time interval in milliseconds after which handler will be notified. */
public get delay() {
return this._delay;
}
public set delay(ms: number) {
this._delay = ms;
}

/** Set handler that is called after a set interval. */
public setOnExecute(onExecute: ExecuteHandler | undefined) {
this._onExecute = onExecute;
}

/** Starts this Timer. */
public start() {
if (this._isRunning) this.clearTimeout();

this._isRunning = true;
this.setTimeout();
}

/** Stops this Timer. */
public stop() {
if (!this._isRunning) return;

this._isRunning = false;
this.clearTimeout();
}

private execute() {
this._onExecute && this._onExecute();
this._isRunning = false;
}

private setTimeout() {
this._timerId = window.setTimeout(() => this.execute(), this._delay);
}

private clearTimeout() {
window.clearTimeout(this._timerId);
}
}
Loading