Skip to content

Commit

Permalink
Consistently use Timers utility module to access clearTimeout, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
msfterictraut committed Apr 20, 2019
1 parent e4906a6 commit a2deb93
Show file tree
Hide file tree
Showing 26 changed files with 57 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/common/utils/AutoFocusHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class FocusArbitratorProvider {
type?: FocusCandidateType): void {

if (_autoFocusTimer) {
clearTimeout(_autoFocusTimer);
Timers.clearTimeout(_autoFocusTimer);
}

const focusArbitratorProvider: FocusArbitratorProvider =
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/FocusManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export abstract class FocusManager {

private static _clearRestoreRestrictionTimeout() {
if (FocusManager._restoreRestrictionTimer) {
clearTimeout(FocusManager._restoreRestrictionTimer);
Timers.clearTimeout(FocusManager._restoreRestrictionTimer);
FocusManager._restoreRestrictionTimer = undefined;
FocusManager._pendingPrevFocusedComponent = undefined;
}
Expand Down
3 changes: 2 additions & 1 deletion src/native-common/ActivityIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as React from 'react';
import * as RN from 'react-native';

import { Types } from '../common/Interfaces';
import Timers from '../common/utils/Timers';

export interface ActivityIndicatorState {
isVisible?: boolean;
Expand All @@ -29,7 +30,7 @@ export class ActivityIndicator extends React.Component<Types.ActivityIndicatorPr
this._isMounted = true;

if (this.props.deferTime && this.props.deferTime > 0) {
setTimeout(() => {
Timers.setTimeout(() => {
if (this._isMounted) {
this.setState({ isVisible: true });
}
Expand Down
4 changes: 2 additions & 2 deletions src/native-common/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class Button extends ButtonBase {
if (this._isTouchFeedbackApplicable()) {
if (this.props.underlayColor) {
if (this._hideTimeout) {
clearTimeout(this._hideTimeout);
Timers.clearTimeout(this._hideTimeout);
this._hideTimeout = undefined;
}
this._showUnderlay();
Expand All @@ -237,7 +237,7 @@ export class Button extends ButtonBase {
if (this._isTouchFeedbackApplicable()) {
if (this.props.underlayColor) {
if (this._hideTimeout) {
clearTimeout(this._hideTimeout);
Timers.clearTimeout(this._hideTimeout);
}
this._hideTimeout = Timers.setTimeout(this._hideUnderlay, _hideUnderlayTimeout);
}
Expand Down
3 changes: 2 additions & 1 deletion src/native-common/FrontLayerViewManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SubscribableEvent from 'subscribableevent';

import { Types } from '../common/Interfaces';
import { ModalContainer } from '../native-common/ModalContainer';
import Timers from '../common/utils/Timers';

import * as _ from './utils/lodashMini';
import PopupContainerView from './PopupContainerView';
Expand Down Expand Up @@ -243,7 +244,7 @@ export class FrontLayerViewManager {
// UI making it not doing one of the two animations (i.e.: Opening an actionsheet
// while dismissing a popup). We introduce this delay to make sure the popup
// dimissing animation has finished before we call the event handler.
setTimeout(() => { activePopupContext.popupOptions.onAnchorPressed!(e); }, 500);
Timers.setTimeout(() => { activePopupContext.popupOptions.onAnchorPressed!(e); }, 500);
}
}
);
Expand Down
4 changes: 2 additions & 2 deletions src/native-common/GestureView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export abstract class GestureView extends React.Component<Types.GestureViewProps
// Cancels any pending double-tap timer.
private _cancelDoubleTapTimer() {
if (this._doubleTapTimer) {
clearTimeout(this._doubleTapTimer);
Timers.clearTimeout(this._doubleTapTimer);
this._doubleTapTimer = undefined;
}
}
Expand All @@ -280,7 +280,7 @@ export abstract class GestureView extends React.Component<Types.GestureViewProps

private _cancelLongPressTimer() {
if (this._longPressTimer) {
clearTimeout(this._longPressTimer);
Timers.clearTimeout(this._longPressTimer);
this._longPressTimer = undefined;
}
this._pendingLongPressEvent = undefined;
Expand Down
3 changes: 2 additions & 1 deletion src/native-common/Popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import assert from '../common/assert';
import * as RX from '../common/Interfaces';
import Timers from '../common/utils/Timers';

import FrontLayerViewManager from './FrontLayerViewManager';

Expand All @@ -23,7 +24,7 @@ export class Popup extends RX.Popup {
autoDismiss(popupId: string, delay?: number): void {
assert(popupId, `popupId must be a non-empty string. Actual: ${ popupId }`);

setTimeout(() => FrontLayerViewManager.dismissPopup(popupId), delay || 0);
Timers.setTimeout(() => FrontLayerViewManager.dismissPopup(popupId), delay || 0);
}

dismiss(popupId: string): void {
Expand Down
2 changes: 1 addition & 1 deletion src/native-common/PopupContainerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class PopupContainerView extends PopupContainerViewBase<PopupContainerVie

private _stopRepositionPopupTimer() {
if (this._respositionPopupTimer) {
clearInterval(this._respositionPopupTimer);
Timers.clearInterval(this._respositionPopupTimer);
this._respositionPopupTimer = undefined;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/native-common/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ export class View extends ViewBase<RX.Types.ViewProps, RX.Types.Stateless, RN.Vi
if (this._isTouchFeedbackApplicable()) {
if (this.props.underlayColor) {
if (this._hideTimeout) {
clearTimeout(this._hideTimeout);
Timers.clearTimeout(this._hideTimeout);
this._hideTimeout = undefined;
}
this._showUnderlay();
Expand All @@ -542,7 +542,7 @@ export class View extends ViewBase<RX.Types.ViewProps, RX.Types.Stateless, RN.Vi
if (this._isTouchFeedbackApplicable()) {
if (this.props.underlayColor) {
if (this._hideTimeout) {
clearTimeout(this._hideTimeout);
Timers.clearTimeout(this._hideTimeout);
}
this._hideTimeout = Timers.setTimeout(this._hideUnderlay, _hideUnderlayTimeout);
}
Expand Down
4 changes: 2 additions & 2 deletions src/native-desktop/RootView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function applyDesktopBehaviorMixin<TRootViewBase extends Constructor<React.Compo
const activeComponent = FocusManager.getCurrentFocusedComponent();

if (this._isNavigatingWithKeyboardUpateTimer) {
clearTimeout(this._isNavigatingWithKeyboardUpateTimer);
Timers.clearTimeout(this._isNavigatingWithKeyboardUpateTimer);
}

this._isNavigatingWithKeyboardUpateTimer = Timers.setTimeout(() => {
Expand All @@ -95,7 +95,7 @@ function applyDesktopBehaviorMixin<TRootViewBase extends Constructor<React.Compo

_updateKeyboardNavigationState(isNavigatingWithKeyboard: boolean) {
if (this._isNavigatingWithKeyboardUpateTimer) {
clearTimeout(this._isNavigatingWithKeyboardUpateTimer);
Timers.clearTimeout(this._isNavigatingWithKeyboardUpateTimer);
this._isNavigatingWithKeyboardUpateTimer = undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion src/native-desktop/utils/FocusManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class FocusManager extends FocusManagerBase {

protected /* static */ resetFocus(focusFirstWhenNavigatingWithKeyboard: boolean) {
if (FocusManager._resetFocusTimer) {
clearTimeout(FocusManager._resetFocusTimer);
Timers.clearTimeout(FocusManager._resetFocusTimer);
FocusManager._resetFocusTimer = undefined;
}

Expand Down
5 changes: 3 additions & 2 deletions src/web/AccessibilityAnnouncer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as React from 'react';
import { SubscriptionToken } from 'subscribableevent';

import { Types } from '../common/Interfaces';
import Timers from '../common/utils/Timers';

import Accessibility from './Accessibility';
import AccessibilityUtil from './AccessibilityUtil';
Expand Down Expand Up @@ -121,15 +122,15 @@ export class AccessibilityAnnouncer extends React.Component<{}, AccessibilityAnn

private _cancelClearAnnouncementTimer() {
if (this._clearAnnouncementTimer) {
clearTimeout(this._clearAnnouncementTimer);
Timers.clearTimeout(this._clearAnnouncementTimer);
this._clearAnnouncementTimer = undefined;
}
}

private _startClearAnnouncementTimer() {
this._cancelClearAnnouncementTimer();

this._clearAnnouncementTimer = window.setTimeout(() => {
this._clearAnnouncementTimer = Timers.setTimeout(() => {
this.setState({
announcementText: ''
});
Expand Down
3 changes: 2 additions & 1 deletion src/web/ActivityIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import * as React from 'react';

import { Types } from '../common/Interfaces';
import Timers from '../common/utils/Timers';

const _activityIndicatorCss = `
.rx-activity {
Expand Down Expand Up @@ -661,7 +662,7 @@ export class ActivityIndicator extends React.Component<Types.ActivityIndicatorPr
this._isMounted = true;

if (this.props.deferTime && this.props.deferTime > 0) {
setTimeout(() => {
Timers.setTimeout(() => {
if (this._isMounted) {
this.setState({ isVisible: true });
}
Expand Down
10 changes: 5 additions & 5 deletions src/web/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class Button extends ButtonBase {

// In the unlikely event we get 2 mouse down events, clear existing timer
if (this._longPressTimer) {
clearTimeout(this._longPressTimer);
Timers.clearTimeout(this._longPressTimer);
}
this._longPressTimer = Timers.setTimeout(() => {
this._longPressTimer = undefined;
Expand Down Expand Up @@ -234,7 +234,7 @@ export class Button extends ButtonBase {

// Touch has left the button, cancel the longpress handler.
if (this._isMouseOver && this._longPressTimer) {
clearTimeout(this._longPressTimer);
Timers.clearTimeout(this._longPressTimer);
}
}

Expand All @@ -244,7 +244,7 @@ export class Button extends ButtonBase {
}

if (this._longPressTimer) {
clearTimeout(this._longPressTimer);
Timers.clearTimeout(this._longPressTimer);
}
}

Expand Down Expand Up @@ -278,7 +278,7 @@ export class Button extends ButtonBase {
}

if (this._longPressTimer) {
clearTimeout(this._longPressTimer);
Timers.clearTimeout(this._longPressTimer);
}
}

Expand All @@ -296,7 +296,7 @@ export class Button extends ButtonBase {

// Cancel longpress if mouse has left.
if (this._longPressTimer) {
clearTimeout(this._longPressTimer);
Timers.clearTimeout(this._longPressTimer);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/web/CustomScrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export class Scrollbar {

dispose() {
if (this._asyncInitTimer) {
clearInterval(this._asyncInitTimer);
Timers.clearInterval(this._asyncInitTimer);
this._asyncInitTimer = undefined;
}
this._stopDrag();
Expand Down
6 changes: 3 additions & 3 deletions src/web/FrontLayerViewManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class FrontLayerViewManager {
this._activePopupShowDelay = showDelay || 0;

if (this._popupShowDelayTimer) {
clearTimeout(this._popupShowDelayTimer);
Timers.clearTimeout(this._popupShowDelayTimer);
this._popupShowDelayTimer = undefined;
}
if (this._activePopupShowDelay > 0) {
Expand All @@ -138,7 +138,7 @@ export class FrontLayerViewManager {
autoDismissPopup(popupId: string, dismissDelay?: number): void {
if (popupId === this._activePopupId && this._activePopupOptions) {
if (this._popupShowDelayTimer) {
clearTimeout(this._popupShowDelayTimer);
Timers.clearTimeout(this._popupShowDelayTimer);
this._popupShowDelayTimer = undefined;
}

Expand All @@ -151,7 +151,7 @@ export class FrontLayerViewManager {
dismissPopup(popupId: string): void {
if (popupId === this._activePopupId && this._activePopupOptions) {
if (this._popupShowDelayTimer) {
clearTimeout(this._popupShowDelayTimer);
Timers.clearTimeout(this._popupShowDelayTimer);
this._popupShowDelayTimer = undefined;
}

Expand Down
4 changes: 2 additions & 2 deletions src/web/GestureView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export class GestureView extends React.Component<Types.GestureViewProps, Types.S

private _cancelLongPressTimer() {
if (this._longPressTimer) {
clearTimeout(this._longPressTimer);
Timers.clearTimeout(this._longPressTimer);
this._longPressTimer = undefined;
}
this._pendingLongPressEvent = undefined;
Expand All @@ -456,7 +456,7 @@ export class GestureView extends React.Component<Types.GestureViewProps, Types.S
// Cancels any pending double-tap timer.
private _cancelDoubleTapTimer() {
if (this._doubleTapTimer) {
clearTimeout(this._doubleTapTimer);
Timers.clearTimeout(this._doubleTapTimer);
this._doubleTapTimer = undefined;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class Image extends React.Component<Types.ImageProps, ImageState> {

private _startXhrImageFetch(props: Types.ImageProps) {
// Test hook to simulate a slower hxr request.
// window.setTimeout(() => this._actuallyStartXhrImageFetch(props), 2500);
// Timers.setTimeout(() => this._actuallyStartXhrImageFetch(props), 2500);
this._actuallyStartXhrImageFetch(props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/web/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class Link extends React.Component<Types.LinkProps, Types.Stateless> {

private _onMouseUp = (e: Types.SyntheticEvent) => {
if (this._longPressTimer) {
clearTimeout(this._longPressTimer);
Timers.clearTimeout(this._longPressTimer);
this._longPressTimer = undefined;
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/web/RootView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export class RootView extends React.Component<RootViewProps, RootViewState> {
// two animations (i.e.: Opening an actionsheet while dismissing a popup). We introduce this delay to make sure
// the popup dimissing animation has finished before we call the event handler.
if (this.props.activePopup.popupOptions.onAnchorPressed) {
setTimeout(() => {
Timers.setTimeout(() => {
// We can't pass through the DOM event argument to the anchor event handler as the event we have at this
// point is a DOM Event and the anchor expect a Synthetic event. There doesn't seem to be any way to convert
// between them. Passing null for now.
Expand Down Expand Up @@ -404,10 +404,10 @@ export class RootView extends React.Component<RootViewProps, RootViewState> {
const activeElement = document.activeElement;

if (this._isNavigatingWithKeyboardUpateTimer) {
clearTimeout(this._isNavigatingWithKeyboardUpateTimer);
Timers.clearTimeout(this._isNavigatingWithKeyboardUpateTimer);
}

this._isNavigatingWithKeyboardUpateTimer = window.setTimeout(() => {
this._isNavigatingWithKeyboardUpateTimer = Timers.setTimeout(() => {
this._isNavigatingWithKeyboardUpateTimer = undefined;

if ((document.activeElement === activeElement) && activeElement && (activeElement !== document.body)) {
Expand All @@ -428,7 +428,7 @@ export class RootView extends React.Component<RootViewProps, RootViewState> {
const target = e.target as HTMLElement;

if (this._updateKeyboardNavigationModeOnFocusTimer) {
clearTimeout(this._updateKeyboardNavigationModeOnFocusTimer);
Timers.clearTimeout(this._updateKeyboardNavigationModeOnFocusTimer);
}

this._updateKeyboardNavigationModeOnFocusTimer = Timers.setTimeout(() => {
Expand Down Expand Up @@ -475,14 +475,14 @@ export class RootView extends React.Component<RootViewProps, RootViewState> {

private _cancelApplicationIsNotActive() {
if (this._applicationIsNotActiveTimer) {
clearTimeout(this._applicationIsNotActiveTimer);
Timers.clearTimeout(this._applicationIsNotActiveTimer);
this._applicationIsNotActiveTimer = undefined;
}
}

private _updateKeyboardNavigationState(isNavigatingWithKeyboard: boolean) {
if (this._isNavigatingWithKeyboardUpateTimer) {
clearTimeout(this._isNavigatingWithKeyboardUpateTimer);
Timers.clearTimeout(this._isNavigatingWithKeyboardUpateTimer);
this._isNavigatingWithKeyboardUpateTimer = undefined;
}

Expand Down Expand Up @@ -525,7 +525,7 @@ export class RootView extends React.Component<RootViewProps, RootViewState> {
if (this.props.autoDismiss) {
// Should we immediately hide it, or did the caller request a delay?
if (!_.isUndefined(this.props.autoDismissDelay) && this.props.autoDismissDelay > 0) {
this._hidePopupTimer = window.setTimeout(() => {
this._hidePopupTimer = Timers.setTimeout(() => {
this._hidePopupTimer = undefined;
this._dismissPopup();
}, this.props.autoDismissDelay);
Expand All @@ -537,7 +537,7 @@ export class RootView extends React.Component<RootViewProps, RootViewState> {

private _stopHidePopupTimer() {
if (this._hidePopupTimer) {
clearTimeout(this._hidePopupTimer);
Timers.clearTimeout(this._hidePopupTimer);
this._hidePopupTimer = undefined;
}
}
Expand All @@ -556,7 +556,7 @@ export class RootView extends React.Component<RootViewProps, RootViewState> {

private _stopRepositionPopupTimer() {
if (this._respositionPopupTimer) {
clearInterval(this._respositionPopupTimer);
Timers.clearInterval(this._respositionPopupTimer);
this._respositionPopupTimer = undefined;
}
}
Expand Down
Loading

0 comments on commit a2deb93

Please sign in to comment.