diff --git a/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/Common/cpp/NativeModules/NativeReanimatedModule.cpp index d0411da81b44..e12b2fd11566 100644 --- a/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -119,9 +119,7 @@ jsi::Value NativeReanimatedModule::startMapper( const jsi::Value &inputs, const jsi::Value &outputs, const jsi::Value &updater, - const jsi::Value &tag, - const jsi::Value &name - ) + const jsi::Value &viewDescriptors) { static unsigned long MAPPER_ID = 1; @@ -136,8 +134,7 @@ jsi::Value NativeReanimatedModule::startMapper( optimalizationLvl = optimalization.asNumber(); } auto updaterSV = ShareableValue::adapt(rt, updater, this); - const int tagInt = tag.asNumber(); - const std::string nameStr = name.asString(rt).utf8(rt); + auto viewDescriptorsSV = ShareableValue::adapt(rt, viewDescriptors, this); scheduler->scheduleOnUI([=] { auto mapperFunction = mapperShareable->getValue(*runtime).asObject(*runtime).asFunction(*runtime); @@ -148,12 +145,11 @@ jsi::Value NativeReanimatedModule::startMapper( newMapperId, mapperFunctionPointer, inputMutables, - outputMutables, - updaterSV, - tagInt, - nameStr, - optimalizationLvl + outputMutables ); + if(optimalizationLvl > 0) { + mapperPointer->enableFastMode(optimalizationLvl, updaterSV, viewDescriptorsSV); + } mapperRegistry->startMapper(mapperPointer); maybeRequestRender(); }); diff --git a/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp b/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp index a48844faaa42..256c92c09348 100644 --- a/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +++ b/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp @@ -52,8 +52,7 @@ static jsi::Value __hostFunction_NativeReanimatedModuleSpec_startMapper( std::move(args[1]), std::move(args[2]), std::move(args[3]), - std::move(args[4]), - std::move(args[5])); + std::move(args[4])); } static jsi::Value __hostFunction_NativeReanimatedModuleSpec_stopMapper( @@ -110,7 +109,7 @@ NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(std::shared_ptr mapper, std::vector> inputs, - std::vector> outputs, - std::shared_ptr updater, - const int viewTag, - const std::string& viewName, - const int optimalizationLvl): + std::vector> outputs): id(id), module(module), mapper(mapper), inputs(inputs), -outputs(outputs), -viewTag(viewTag), -optimalizationLvl(optimalizationLvl) +outputs(outputs) { - jsi::Runtime* rt = module->runtime.get(); - this->viewName = jsi::Value(*rt, jsi::String::createFromUtf8(*rt, viewName)); - updateProps = &module->updaterFunction; - userUpdater = std::make_shared(updater->getValue(*rt).asObject(*rt).asFunction(*rt)); - - auto markDirty = [this, module]() { this->dirty = true; module->maybeRequestRender(); @@ -39,11 +27,40 @@ optimalizationLvl(optimalizationLvl) void Mapper::execute(jsi::Runtime &rt) { dirty = false; if(optimalizationLvl == 0) { - mapper->callWithThis(rt, *mapper);// call styleUpdater + mapper->callWithThis(rt, *mapper); // call styleUpdater } else { - (*updateProps)(rt, viewTag, viewName, userUpdater->call(rt).asObject(rt)); + for(auto& viewDescriptor : viewDescriptors) { + (*updateProps)(rt, viewDescriptor.tag, viewDescriptor.name, userUpdater->call(rt).asObject(rt)); + } + } +} + +void Mapper::enableFastMode( + const int optimalizationLvl, + const std::shared_ptr& updater, + const std::shared_ptr& jsViewDescriptors +) { + if(optimalizationLvl == 0) { + return; } + this->optimalizationLvl = optimalizationLvl; + updateProps = &module->updaterFunction; + jsi::Runtime* rt = module->runtime.get(); + userUpdater = std::make_shared(updater->getValue(*rt).asObject(*rt).asFunction(*rt)); + auto jsViewDescriptorArray = jsViewDescriptors->getValue(*rt) + .getObject(*rt) + .getProperty(*rt, "value") + .asObject(*rt) + .getArray(*rt); + for(int i = 0; i < jsViewDescriptorArray.length(*rt); ++i) { + auto jsViewDescriptor = jsViewDescriptorArray.getValueAtIndex(*rt, i).getObject(*rt); + viewDescriptors.push_back(ViewDescriptor { + (int)jsViewDescriptor.getProperty(*rt, "tag").asNumber(), + jsViewDescriptor.getProperty(*rt, "name"), + }); + } + } Mapper::~Mapper() { diff --git a/Common/cpp/headers/NativeModules/NativeReanimatedModule.h b/Common/cpp/headers/NativeModules/NativeReanimatedModule.h index 23c4c63fd318..ea4291652193 100644 --- a/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +++ b/Common/cpp/headers/NativeModules/NativeReanimatedModule.h @@ -48,8 +48,7 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec, public Runtime const jsi::Value &inputs, const jsi::Value &outputs, const jsi::Value &updater, - const jsi::Value &tag, - const jsi::Value &name) override; + const jsi::Value &viewDescriptors) override; void stopMapper(jsi::Runtime &rt, const jsi::Value &mapperId) override; jsi::Value registerEventHandler(jsi::Runtime &rt, const jsi::Value &eventHash, const jsi::Value &worklet) override; diff --git a/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h b/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h index 74ca43b24e3b..b6a02ec3a59d 100644 --- a/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +++ b/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h @@ -36,8 +36,7 @@ class JSI_EXPORT NativeReanimatedModuleSpec : public TurboModule { const jsi::Value &inputs, const jsi::Value &outputs, const jsi::Value &updater, - const jsi::Value &tag, - const jsi::Value &name) = 0; + const jsi::Value &viewDescriptors) = 0; virtual void stopMapper(jsi::Runtime &rt, const jsi::Value &mapperId) = 0; // events diff --git a/Common/cpp/headers/Tools/Mapper.h b/Common/cpp/headers/Tools/Mapper.h index 95a50e4067c8..55a7d23733d9 100644 --- a/Common/cpp/headers/Tools/Mapper.h +++ b/Common/cpp/headers/Tools/Mapper.h @@ -11,6 +11,11 @@ namespace reanimated { class MapperRegistry; +struct ViewDescriptor { + int tag; + jsi::Value name; +}; + class Mapper : public std::enable_shared_from_this { friend MapperRegistry; private: @@ -22,8 +27,7 @@ class Mapper : public std::enable_shared_from_this { bool dirty = true; std::shared_ptr userUpdater; UpdaterFunction* updateProps; - jsi::Value viewName; - int viewTag; + std::vector viewDescriptors; int optimalizationLvl = 0; public: @@ -31,12 +35,13 @@ class Mapper : public std::enable_shared_from_this { unsigned long id, std::shared_ptr mapper, std::vector> inputs, - std::vector> outputs, - std::shared_ptr updater, - const int viewTag, - const std::string& viewName, - const int optimalizationLvl); + std::vector> outputs); void execute(jsi::Runtime &rt); + void enableFastMode( + const int optimalizationLvl, + const std::shared_ptr& updater, + const std::shared_ptr&jsViewDescriptors + ); virtual ~Mapper(); }; diff --git a/Example/src/AnimatedStyleUpdateExample.tsx b/Example/src/AnimatedStyleUpdateExample.tsx index 9ca070308ccc..1745697317c6 100644 --- a/Example/src/AnimatedStyleUpdateExample.tsx +++ b/Example/src/AnimatedStyleUpdateExample.tsx @@ -43,4 +43,4 @@ function AnimatedStyleUpdateExample(): React.ReactElement { ); } -export default AnimatedStyleUpdateExample; +export default AnimatedStyleUpdateExample; \ No newline at end of file diff --git a/plugin.js b/plugin.js index 2960c231e08e..78f4772c8faf 100644 --- a/plugin.js +++ b/plugin.js @@ -121,6 +121,7 @@ const blacklistedFunctions = new Set([ 'apply', 'call', '__callAsync', + 'includes', ]); const possibleOptFunction = new Set(['interpolate']); @@ -275,7 +276,7 @@ function buildWorkletString(t, fun, closureVariables, name) { return generate(workletFunction, { compact: true }).code; } -function processWorkletFunction(t, fun, fileName, options = {}) { +function processWorkletFunction(t, fun, fileName) { if (!t.isFunctionParent(fun)) { return; } @@ -284,6 +285,7 @@ function processWorkletFunction(t, fun, fileName, options = {}) { const closure = new Map(); const outputs = new Set(); const closureGenerator = new ClosureGenerator(); + const options = {}; // We use copy because some of the plugins don't update bindings and // some even break them @@ -302,7 +304,13 @@ function processWorkletFunction(t, fun, fileName, options = {}) { babelrc: false, configFile: false, }); - + if ( + fun.parent && + fun.parent.callee && + fun.parent.callee.name === 'useAnimatedStyle' + ) { + options.optFlags = isPossibleOptimization(transformed.ast); + } traverse(transformed.ast, { ReferencedIdentifier(path) { const name = path.node.name; @@ -498,12 +506,7 @@ function processIfWorkletNode(t, fun, fileName) { directive.value.value === 'worklet' ) ) { - const flags = isPossibleOptimization(fun); - if (flags) { - processWorkletFunction(t, fun, fileName, { optFlags: flags }); - } else { - processWorkletFunction(t, fun, fileName); - } + processWorkletFunction(t, fun, fileName); } } }, @@ -547,7 +550,7 @@ const STATEMENTLESS_FLAG = 0b00000010; function isPossibleOptimization(fun) { let isFunctionCall = false; let isSteatements = false; - fun.scope.path.traverse({ + traverse(fun, { CallExpression(path) { if (!possibleOptFunction.has(path.node.callee.name)) { isFunctionCall = true; diff --git a/src/createAnimatedComponent.js b/src/createAnimatedComponent.js index d039560a82dd..5a48cb4a2cdf 100644 --- a/src/createAnimatedComponent.js +++ b/src/createAnimatedComponent.js @@ -73,6 +73,8 @@ export default function createAnimatedComponent(Component, options = {}) { class AnimatedComponent extends React.Component { _invokeAnimatedPropsCallbackOnMount = false; + _styles = null; + _viewTag = -1; constructor(props) { super(props); @@ -87,6 +89,7 @@ export default function createAnimatedComponent(Component, options = {}) { this._detachPropUpdater(); this._propsAnimated && this._propsAnimated.__detach(); this._detachNativeEvents(); + this._detachStyles(); this.sv = null; } @@ -143,6 +146,25 @@ export default function createAnimatedComponent(Component, options = {}) { } } + _detachStyles() { + if (Platform.OS === 'web') { + for (const style of this._styles) { + if (style.viewsRef) { + style.viewsRef.remove(this); + } + } + } else if (this._viewTag !== -1) { + for (const style of this._styles) { + if (style?.viewDescriptors) { + style.viewDescriptors.remove(this._viewTag); + } + } + if (this.props.animatedProps?.viewDescriptors) { + this.props.animatedProps.viewDescriptors.remove(this._viewTag); + } + } + } + _reattachNativeEvents(prevProps) { const node = this._getEventViewRef(); const attached = new Set(); @@ -261,6 +283,7 @@ export default function createAnimatedComponent(Component, options = {}) { ? this.props.style : [this.props.style]; styles = flattenArray(styles); + this._styles = styles; let viewTag, viewName; if (Platform.OS === 'web') { viewTag = findNodeHandle(this); @@ -289,10 +312,11 @@ export default function createAnimatedComponent(Component, options = {}) { adaptViewConfig(hostInstance.viewConfig); } } + this._viewTag = viewTag; styles.forEach((style) => { - if (style?.viewDescriptor) { - style.viewDescriptor.value = { tag: viewTag, name: viewName }; + if (style?.viewDescriptors) { + style.viewDescriptors.add({ tag: viewTag, name: viewName }); if (process.env.JEST_WORKER_ID) { /** * We need to connect Jest's TestObject instance whose contains just props object @@ -302,29 +326,29 @@ export default function createAnimatedComponent(Component, options = {}) { */ this.animatedStyle.value = { ...this.animatedStyle.value, - ...style.initial, + ...style.initial.value, }; style.animatedStyle.current = this.animatedStyle; } } }); // attach animatedProps property - if (this.props.animatedProps?.viewDescriptor) { - this.props.animatedProps.viewDescriptor.value = { + if (this.props.animatedProps?.viewDescriptors) { + this.props.animatedProps.viewDescriptors.add({ tag: viewTag, name: viewName, - }; + }); } } _hasReanimated2Props(flattenStyles) { - if (this.props.animatedProps?.viewDescriptor) { + if (this.props.animatedProps?.viewDescriptors) { return true; } if (this.props.style) { for (const style of flattenStyles) { // eslint-disable-next-line no-prototype-builtins - if (style?.hasOwnProperty('viewDescriptor')) { + if (style?.hasOwnProperty('viewDescriptors')) { return true; } } @@ -345,6 +369,7 @@ export default function createAnimatedComponent(Component, options = {}) { this._reattachNativeEvents(prevProps); this._propsAnimated && this._propsAnimated.setNativeView(this._component); + this._attachAnimatedStyles(); } _setComponentRef = setAndForwardRef({ @@ -430,12 +455,10 @@ export default function createAnimatedComponent(Component, options = {}) { if (key === 'style') { const styles = Array.isArray(value) ? value : [value]; const processedStyle = styles.map((style) => { - if (style && style.viewDescriptor) { + if (style && style.viewDescriptors) { // this is how we recognize styles returned by useAnimatedStyle - if (style.viewRef.current === null) { - style.viewRef.current = this; - } - return style.initial; + style.viewsRef.add(this); + return style.initial.value; } else { return style; } @@ -444,11 +467,9 @@ export default function createAnimatedComponent(Component, options = {}) { StyleSheet.flatten(processedStyle) ); } else if (key === 'animatedProps') { - Object.keys(value.initial).forEach((key) => { - props[key] = value.initial[key]; - if (value.viewRef.current === null) { - value.viewRef.current = this; - } + Object.keys(value.initial.value).forEach((key) => { + props[key] = value.initial.value[key]; + value.viewsRef.add(this); }); } else if (value instanceof AnimatedEvent) { // we cannot filter out event listeners completely as some components diff --git a/src/reanimated2/Hooks.ts b/src/reanimated2/Hooks.ts index 203f5f0336c7..eb0a735b25ef 100644 --- a/src/reanimated2/Hooks.ts +++ b/src/reanimated2/Hooks.ts @@ -17,6 +17,7 @@ import { initialUpdaterRun, cancelAnimation } from './animations'; import { getTag } from './NativeMethods'; import NativeReanimated from './NativeReanimated'; import { Platform } from 'react-native'; +import { makeViewDescriptorsSet, makeViewsRefSet } from './ViewDescriptorsSet'; import { processColor } from './Colors'; export function useSharedValue(init) { @@ -230,7 +231,7 @@ const validateAnimatedStyles = (styles) => { }; function styleUpdater( - viewDescriptor, + viewDescriptors, updater, state, maybeViewRef, @@ -280,7 +281,7 @@ function styleUpdater( } if (updates) { - updateProps(viewDescriptor, updates, maybeViewRef); + updateProps(viewDescriptors, updates, maybeViewRef); } if (!allFinished) { @@ -303,17 +304,17 @@ function styleUpdater( state.last = Object.assign({}, oldValues, newValues); const style = getStyleWithoutAnimations(oldValues, newValues); if (style) { - updateProps(viewDescriptor, style, maybeViewRef); + updateProps(viewDescriptors, style, maybeViewRef); } } else { state.isAnimationCancelled = true; state.animations = {}; - updateProps(viewDescriptor, newValues, maybeViewRef); + updateProps(viewDescriptors, newValues, maybeViewRef); } } function jestStyleUpdater( - viewDescriptor, + viewDescriptors, updater, state, maybeViewRef, @@ -370,7 +371,7 @@ function jestStyleUpdater( if (Object.keys(updates).length) { updatePropsJestWrapper( - viewDescriptor, + viewDescriptors, updates, maybeViewRef, animatedStyle, @@ -407,7 +408,7 @@ function jestStyleUpdater( if (Object.keys(diff).length !== 0) { updatePropsJestWrapper( - viewDescriptor, + viewDescriptors, diff, maybeViewRef, animatedStyle, @@ -444,10 +445,10 @@ const canApplyOptimalisation = (upadterFn) => { }; export function useAnimatedStyle(updater, dependencies, adapters) { - const viewDescriptor = useSharedValue({ tag: -1, name: null }, false); const initRef = useRef(null); + const viewsRef = makeViewsRefSet(); + const viewDescriptors = makeViewDescriptorsSet(); const inputs = Object.values(updater._closure); - const viewRef = useRef(null); adapters = !adapters || Array.isArray(adapters) ? adapters : [adapters]; const adaptersHash = adapters ? buildWorkletsHash(adapters) : null; const animationsActive = useSharedValue(true); @@ -465,17 +466,25 @@ export function useAnimatedStyle(updater, dependencies, adapters) { adaptersHash && dependencies.push(adaptersHash); if (initRef.current === null) { - const initial = initialUpdaterRun(updater); - validateAnimatedStyles(initial); + const initialStyle = initialUpdaterRun(updater); + validateAnimatedStyles(initialStyle); initRef.current = { - initial, - remoteState: makeRemote({ last: initial }), + initial: { + value: null, + }, + remoteState: makeRemote({ last: initialStyle }), + sharableViewDescriptors: makeMutable([]), }; + viewDescriptors.rebuildsharableViewDescriptors( + initRef.current.sharableViewDescriptors + ); } + dependencies.push(initRef.current.sharableViewDescriptors.value); - const { remoteState, initial } = initRef.current; - const maybeViewRef = NativeReanimated.native ? undefined : viewRef; + const { initial, remoteState, sharableViewDescriptors } = initRef.current; + const maybeViewRef = NativeReanimated.native ? undefined : viewsRef; + initial.value = initialUpdaterRun(updater); useEffect(() => { let fun; let upadterFn = updater; @@ -517,7 +526,7 @@ export function useAnimatedStyle(updater, dependencies, adapters) { fun = () => { 'worklet'; jestStyleUpdater( - viewDescriptor, + sharableViewDescriptors, updater, remoteState, maybeViewRef, @@ -530,7 +539,7 @@ export function useAnimatedStyle(updater, dependencies, adapters) { fun = () => { 'worklet'; styleUpdater( - viewDescriptor, + sharableViewDescriptors, upadterFn, remoteState, maybeViewRef, @@ -538,13 +547,13 @@ export function useAnimatedStyle(updater, dependencies, adapters) { ); }; } + const mapperId = startMapper( fun, inputs, [], upadterFn, - viewDescriptor.value.tag, - viewDescriptor.value.name || 'RCTView' + sharableViewDescriptors ); return () => { stopMapper(mapperId); @@ -554,8 +563,8 @@ export function useAnimatedStyle(updater, dependencies, adapters) { useEffect(() => { animationsActive.value = true; return () => { - initRef.current = null; - viewRef.current = null; + // initRef.current = null; + // viewsRef = null; animationsActive.value = false; }; }, []); @@ -597,9 +606,9 @@ export function useAnimatedStyle(updater, dependencies, adapters) { } if (process.env.JEST_WORKER_ID) { - return { viewDescriptor, initial, viewRef, animatedStyle }; + return { viewDescriptors, initial, viewsRef, animatedStyle }; } else { - return { viewDescriptor, initial, viewRef }; + return { viewDescriptors, initial, viewsRef }; } } diff --git a/src/reanimated2/UpdateProps.ts b/src/reanimated2/UpdateProps.ts index d7c3d6d02b4d..961ca70aa610 100644 --- a/src/reanimated2/UpdateProps.ts +++ b/src/reanimated2/UpdateProps.ts @@ -28,12 +28,14 @@ const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps); let updatePropsByPlatform; if (Platform.OS === 'web' || process.env.JEST_WORKER_ID) { - updatePropsByPlatform = (viewDescriptor, updates, maybeViewRef) => { + updatePropsByPlatform = (_, updates, maybeViewRef) => { 'worklet'; - _updatePropsJS(viewDescriptor.value.tag, null, updates, maybeViewRef); + maybeViewRef.items.forEach((item, _) => { + _updatePropsJS(updates, item); + }); }; } else { - updatePropsByPlatform = (viewDescriptor, updates, _) => { + updatePropsByPlatform = (viewDescriptors, updates, _) => { 'worklet'; for (const key in updates) { @@ -42,18 +44,20 @@ if (Platform.OS === 'web' || process.env.JEST_WORKER_ID) { } } - _updateProps( - viewDescriptor.value.tag, - viewDescriptor.value.name || 'RCTView', - updates - ); + viewDescriptors.value.forEach((viewDescriptor) => { + _updateProps( + viewDescriptor.tag, + viewDescriptor.name || 'RCTView', + updates + ); + }); }; } export const updateProps = updatePropsByPlatform; export const updatePropsJestWrapper = ( - viewDescriptor, + viewDescriptors, updates, maybeViewRef, animatedStyle, @@ -67,7 +71,7 @@ export const updatePropsJestWrapper = ( ...updates, }; - updateProps(viewDescriptor, updates, maybeViewRef); + updateProps(viewDescriptors, updates, maybeViewRef); }; export default updateProps; diff --git a/src/reanimated2/ViewDescriptorsSet.ts b/src/reanimated2/ViewDescriptorsSet.ts new file mode 100644 index 000000000000..5f14a25ab4f3 --- /dev/null +++ b/src/reanimated2/ViewDescriptorsSet.ts @@ -0,0 +1,86 @@ +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-nocheck +import { useRef } from 'react'; +import { makeMutable } from './core'; + +export function makeViewDescriptorsSet() { + const ref = useRef(null); + if (ref.current === null) { + const data = { + batchToRemove: new Set(), + tags: new Set(), + waitForInsertSync: false, + waitForRemoveSync: false, + sharableViewDescriptors: makeMutable([]), + items: [], + + add: (item) => { + if (data.tags.has(item.tag)) { + return; + } + data.tags.add(item.tag); + data.items.push(item); + + if (!data.waitForInsertSync) { + data.waitForInsertSync = true; + + setImmediate(() => { + data.sharableViewDescriptors.value = data.items; + data.waitForInsertSync = false; + }); + } + }, + + remove: (viewTag) => { + data.batchToRemove.add(viewTag); + + if (!data.waitForRemoveSync) { + data.waitForRemoveSync = true; + + setImmediate(() => { + const items = []; + for (const item of data.items) { + if (data.batchToRemove.has(item.tag)) { + data.tags.delete(item.tag); + } else { + items.push(item); + } + } + data.items = items; + data.sharableViewDescriptors.value = items; + data.batchToRemove = new Set(); + data.waitForRemoveSync = false; + }); + } + }, + + rebuildsharableViewDescriptors: (sharableViewDescriptors) => { + data.sharableViewDescriptors = sharableViewDescriptors; + }, + }; + ref.current = data; + } + + return ref.current; +} + +export function makeViewsRefSet() { + const ref = useRef(null); + if (ref.current === null) { + const data = { + items: new Set(), + + add: (item) => { + if (data.items.has(item)) return; + data.items.add(item); + }, + + remove: (item) => { + data.items.delete(item); + }, + }; + ref.current = data; + } + + return ref.current; +} diff --git a/src/reanimated2/core.ts b/src/reanimated2/core.ts index 76ab6c9c2e66..716dfc4e685d 100644 --- a/src/reanimated2/core.ts +++ b/src/reanimated2/core.ts @@ -266,8 +266,7 @@ export function startMapper( updater = () => { // noop }, - tag = 0, - name = '' + viewDescriptors = [] ) { isConfiguredCheck(); return NativeReanimated.startMapper( @@ -275,8 +274,7 @@ export function startMapper( inputs, outputs, updater, - tag, - name + viewDescriptors ); } diff --git a/src/reanimated2/js-reanimated/index.js b/src/reanimated2/js-reanimated/index.js deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/src/reanimated2/js-reanimated/index.web.ts b/src/reanimated2/js-reanimated/index.web.ts index e3abc218345c..8da96709dd81 100644 --- a/src/reanimated2/js-reanimated/index.web.ts +++ b/src/reanimated2/js-reanimated/index.web.ts @@ -6,8 +6,8 @@ const reanimatedJS = new JSReanimated(); global._frameTimestamp = null; -export const _updatePropsJS = (_viewTag, _viewName, updates, viewRef) => { - if (viewRef.current && viewRef.current._component) { +export const _updatePropsJS = (updates, viewRef) => { + if (viewRef?._component) { const [rawStyles] = Object.keys(updates).reduce( (acc, key) => { const value = updates[key]; @@ -18,15 +18,15 @@ export const _updatePropsJS = (_viewTag, _viewName, updates, viewRef) => { [{}, {}] ); - if (typeof viewRef.current._component.setNativeProps === 'function') { - viewRef.current._component.setNativeProps({ style: rawStyles }); - } else if (Object.keys(viewRef.current._component.props).length > 0) { - Object.keys(viewRef.current._component.props).forEach((key) => { + if (typeof viewRef._component.setNativeProps === 'function') { + viewRef._component.setNativeProps({ style: rawStyles }); + } else if (Object.keys(viewRef._component.props).length > 0) { + Object.keys(viewRef._component.props).forEach((key) => { if (!rawStyles[key]) { return; } const dashedKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase()); - viewRef.current._component._touchableNode.setAttribute( + viewRef._component._touchableNode.setAttribute( dashedKey, rawStyles[key] );