Skip to content

Commit

Permalink
Declare logger as a global variable to fix circular imports
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiPl01 committed Aug 7, 2024
1 parent 039feb1 commit 8a0af5a
Show file tree
Hide file tree
Showing 51 changed files with 51 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/uimanager/UIManager.h>

#include <type_traits>
#include <memory>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
Expand All @@ -15,8 +15,10 @@ using namespace react;

namespace reanimated {

using PropsMap = std::unordered_map<const ShadowNodeFamily *, std::vector<RawProps>>;
using ChildrenMap = std::unordered_map<const ShadowNodeFamily *, std::unordered_set<int>>;
using PropsMap =
std::unordered_map<const ShadowNodeFamily *, std::vector<RawProps>>;
using ChildrenMap =
std::unordered_map<const ShadowNodeFamily *, std::unordered_set<int>>;

RootShadowNode::Unshared cloneShadowTreeWithNewProps(
const RootShadowNode &oldRootNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ ShareableObject::ShareableObject(
jsi::Value ShareableObject::toJSValue(jsi::Runtime &rt) {
auto obj = jsi::Object(rt);
for (size_t i = 0, size = data_.size(); i < size; i++) {
obj.setProperty(rt, jsi::String::createFromUtf8(rt, data_[i].first), data_[i].second->toJSValue(rt));
obj.setProperty(
rt,
jsi::String::createFromUtf8(rt, data_[i].first),
data_[i].second->toJSValue(rt));
}
#if SUPPORTS_NATIVE_STATE
if (nativeState_ != nullptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void WorkletRuntimeDecorator::decorate(
for (size_t i = 0; i < argsSize; i++) {
args[i] = argsArray.getValueAtIndex(rt, i);
}
remoteFun.asObject(rt).asFunction(rt).call(rt, const_cast<const jsi::Value *>(args.data()), args.size());
remoteFun.asObject(rt).asFunction(rt).call(
rt, const_cast<const jsi::Value *>(args.data()), args.size());
}
});
});
Expand Down
2 changes: 0 additions & 2 deletions packages/react-native-reanimated/src/Bezier.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { logger } from './logger';

/**
* https://github.com/gre/bezier-easing
* BezierEasing - use bezier curve for transition easing function
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-reanimated/src/ConfigHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
import { PropsAllowlists } from './propsAllowlists';
import { jsiConfigureProps } from './core';
import { logger } from './logger';

function assertNoOverlapInLists() {
for (const key in PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST) {
if (key in PropsAllowlists.UI_THREAD_PROPS_WHITELIST) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type React from 'react';
import { getShadowNodeWrapperFromRef } from '../fabricUtils';
import type { LayoutAnimationBatchItem } from '../layoutReanimation/animationBuilder/commonTypes';
import ReanimatedModule from '../specs/NativeReanimatedModule';
import { logger } from '../logger';

// this is the type of `__reanimatedModuleProxy` which is injected using JSI
export interface NativeReanimatedModule {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-reanimated/src/PropsRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
import { logger } from './logger';

import { isFabric } from './PlatformChecker';
import { runOnUI } from './threads';

Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/UpdateProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type { ReanimatedHTMLElement } from './js-reanimated';
import { _updatePropsJS } from './js-reanimated';
import { isFabric, isJest, shouldBeUseWeb } from './PlatformChecker';
import { runOnUIImmediately } from './threads';
import { logger } from './logger';

let updateProps: (
viewDescriptor: SharedValue<Descriptor[]>,
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/animation/clamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
ReduceMotion,
} from '../commonTypes';
import type { ClampAnimation } from './commonTypes';
import { logger } from '../logger';

type withClampType = <T extends number | string>(
config: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {
InnerDecayAnimation,
} from './utils';
import { rigidDecay } from './rigidDecay';
import { logger } from '../../logger';

export type WithDecayConfig = DecayConfig;

Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/animation/sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
ReduceMotion,
Timestamp,
} from '../commonTypes';
import { logger } from '../logger';

/**
* Lets you run animations in a sequence.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
Timestamp,
ReduceMotion,
} from '../commonTypes';
import { logger } from '../logger';

/**
* Spring animation configuration.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { logger } from '../../logger';

type FixedLengthArray<
T,
L extends number,
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/animation/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
import { shouldBeUseWeb } from '../PlatformChecker';
import type { EasingFunctionFactory } from '../Easing';
import { ReducedMotionManager } from '../ReducedMotion';
import { logger } from '../logger';

let IN_STYLE_UPDATER = false;
const SHOULD_BE_USE_WEB = shouldBeUseWeb();
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/animationBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
} from './layoutReanimation';
import type { StyleProps } from './commonTypes';
import type { NestedArray } from './createAnimatedComponent/commonTypes';
import { logger } from './logger';

const mockTargetValues: LayoutAnimationsValues = {
targetOriginX: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ReducedMotionManager,
isReducedMotionEnabledInSystem,
} from '../ReducedMotion';
import { logger } from '../logger';

/**
* A component that lets you overwrite default reduce motion behavior globally in your application.
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { makeShareableCloneRecursive } from './shareables';
import { initializeUIRuntime } from './initializers';
import type { LayoutAnimationBatchItem } from './layoutReanimation/animationBuilder/commonTypes';
import { SensorContainer } from './SensorContainer';
import { logger } from './logger';

export { startMapper, stopMapper } from './mappers';
export { runOnJS, runOnUI, executeOnUIRuntimeSync } from './threads';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import { addHTMLMutationObserver } from '../layoutReanimation/web/domUtils';
import { getViewInfo } from './getViewInfo';
import { NativeEventsManager } from './NativeEventsManager';
import type { ReanimatedHTMLElement } from '../js-reanimated';
import { logger } from '../logger';

const IS_WEB = isWeb();

Expand Down
2 changes: 0 additions & 2 deletions packages/react-native-reanimated/src/fabricUtils.web.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { logger } from './logger';

export function getShadowNodeWrapperFromRef() {
throw logger.newError('Trying to call `getShadowNodeWrapperFromRef` on web.');
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import type {
AnimatedStyle,
} from '../commonTypes';
import { isWorkletFunction } from '../commonTypes';
import { logger } from '../logger';

const SHOULD_BE_USE_WEB = shouldBeUseWeb();

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-reanimated/src/hook/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
import type { WorkletFunction } from '../commonTypes';
import { logger } from '../logger';

import type { DependencyList } from './commonTypes';

// Builds one big hash from multiple worklets' hashes.
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/interpolateColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { makeMutable } from './core';
import { Extrapolation, interpolate } from './interpolation';
import type { SharedValue } from './commonTypes';
import { useSharedValue } from './hook/useSharedValue';
import { logger } from './logger';

/**
* @deprecated Please use Extrapolation instead
Expand Down
2 changes: 0 additions & 2 deletions packages/react-native-reanimated/src/interpolation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { logger } from './logger';

/**
* Extrapolation type.
*
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/jestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
} from './createAnimatedComponent/commonTypes';
import { isJest } from './PlatformChecker';
import type { DefaultStyle } from './hook/commonTypes';
import { logger } from './logger';

declare global {
namespace jest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { SensorType } from '../commonTypes';
import type { WebSensor } from './WebSensor';
import { mockedRequestAnimationFrame } from '../mockedRequestAnimationFrame';
import type { WorkletRuntime } from '../runtimes';
import { logger } from '../logger';

// In Node.js environments (like when static rendering with Expo Router)
// requestAnimationFrame is unavailable, so we use our mock.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
createTextShadowValue,
} from './webUtils';
import { PropsAllowlists } from '../propsAllowlists';
import { logger } from '../logger';

const reanimatedJS = new JSReanimated();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {

import { ReduceMotion } from '../../commonTypes';
import { getReduceMotionFromConfig } from '../../animation/util';
import { logger } from '../../logger';

export class BaseAnimationBuilder {
durationV?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
assertEasingIsWorklet,
getReduceMotionFromConfig,
} from '../../animation/util';
import { logger } from '../../logger';

interface KeyframePoint {
duration: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
import { registerEventHandler, unregisterEventHandler } from '../../core';
import { Platform } from 'react-native';
import { isJest, shouldBeUseWeb } from '../../PlatformChecker';
import { logger } from '../../logger';

type TransitionProgressEvent = {
closing: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ReduceMotion } from '../../commonTypes';
import { ProgressTransitionManager } from './ProgressTransitionManager';
import { updateLayoutAnimations } from '../../UpdateLayoutAnimations';
import { getReduceMotionFromConfig } from '../../animation/util';
import { logger } from '../../logger';

const SUPPORTED_PROPS = [
'width',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { Keyframe } from '../animationBuilder';
import { makeElementVisible } from './componentStyle';
import { EasingNameSymbol } from '../../Easing';
import type { ReanimatedHTMLElement } from '../../js-reanimated';
import { logger } from '../../logger';

function chooseConfig<ComponentProps extends Record<string, unknown>>(
animationType: LayoutAnimationType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { Keyframe } from '../animationBuilder';
import { ReducedMotionManager } from '../../ReducedMotion';
import { prepareCurvedTransition } from './transition/Curved.web';
import { EasingNameSymbol } from '../../Easing';
import { logger } from '../../logger';

function getEasingFromConfig(config: CustomConfig): string {
if (!config.easingV) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import type { ReanimatedHTMLElement } from '../../js-reanimated';
import { logger } from '../../logger';

import { isWindowAvailable } from '../../PlatformChecker';
import { setElementPosition, snapshots } from './componentStyle';
import { Animations } from './config';
Expand Down
2 changes: 0 additions & 2 deletions packages/react-native-reanimated/src/logger/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react-native-reanimated/src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ function createLogger(prefix: string) {
};
}

export const logger = createLogger('[Reanimated]');
global.logger = createLogger('[Reanimated]');
2 changes: 1 addition & 1 deletion packages/react-native-reanimated/src/mutables.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
import { shouldBeUseWeb } from './PlatformChecker';
import type { Mutable } from './commonTypes';
import { logger } from './logger';

import { shareableMappingCache } from './shareableMappingCache';
import { makeShareableCloneRecursive } from './shareables';
import { executeOnUIRuntimeSync, runOnUI } from './threads';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
import { logger } from '../logger';

import { jsVersion } from './jsVersion';

export function checkCppVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
AnimatedRefOnUI,
} from '../hook/commonTypes';
import type { Component } from 'react';
import { logger } from '../logger';

type DispatchCommand = <T extends Component>(
animatedRef: AnimatedRef<T>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { logger } from '../logger';

export function dispatchCommand() {
logger.warn('dispatchCommand() is not supported on web.');
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
AnimatedRefOnUI,
} from '../hook/commonTypes';
import type { Component } from 'react';
import { logger } from '../logger';

type Measure = <T extends Component>(
animatedRef: AnimatedRef<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import type { MeasuredDimensions } from '../commonTypes';
import type { AnimatedRef } from '../hook/commonTypes';
import type { Component } from 'react';
import { logger } from '../logger';

export function measure<T extends Component>(
animatedRef: AnimatedRef<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
AnimatedRefOnUI,
} from '../hook/commonTypes';
import type { Component } from 'react';
import { logger } from '../logger';

type ScrollTo = <T extends Component>(
animatedRef: AnimatedRef<T>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
import { logger } from '../logger';

import { isChromeDebugger, isJest, shouldBeUseWeb } from '../PlatformChecker';

type SetGestureState = (handlerTag: number, newState: number) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { logger } from '../logger';

export function setGestureState() {
logger.warn('setGestureState() is not available on web.');
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
} from '../hook/commonTypes';
import type { Component } from 'react';
import { processColorsInProps } from '../Colors';
import { logger } from '../logger';

type SetNativeProps = <T extends Component>(
animatedRef: AnimatedRef<T>,
Expand Down
12 changes: 12 additions & 0 deletions packages/react-native-reanimated/src/publicGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,16 @@ declare global {
* which is the Reanimated UI runtime.
*/
var _WORKLET_RUNTIME: ArrayBuffer;

/**
* Logger is set as a global variable for easier usage without the
* necessity of importing it in every file. It also caused circular
* dependencies as it imports runOnJS.
*/
var logger: {
warn: (message: string) => void;
error: (message: string) => void;
fatal: (message: string) => void;
newError: (message: string) => never;
};
}
2 changes: 1 addition & 1 deletion packages/react-native-reanimated/src/runtimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { isWorkletFunction } from './commonTypes';
import type { WorkletFunction } from './commonTypes';
import { setupCallGuard, setupConsole } from './initializers';
import { logger } from './logger';

import NativeReanimatedModule from './NativeReanimated';
import { shouldBeUseWeb } from './PlatformChecker';
import {
Expand Down
Loading

0 comments on commit 8a0af5a

Please sign in to comment.