react-native-reanimated
Version:
More powerful alternative to Animated library for React Native.
89 lines (84 loc) • 2.4 kB
JavaScript
import { processColorsInProps } from './Colors';
import { _updatePropsJS } from './js-reanimated';
import { shouldBeUseWeb } from './PlatformChecker';
import { runOnUIImmediately } from './threads';
let updateProps;
if (shouldBeUseWeb()) {
updateProps = (_, updates, maybeViewRef, isAnimatedProps) => {
'worklet';
if (maybeViewRef) {
maybeViewRef.items.forEach((item, _) => {
_updatePropsJS(updates, item, isAnimatedProps);
});
}
};
} else {
updateProps = (viewDescriptors, updates) => {
'worklet';
processColorsInProps(updates);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
global.UpdatePropsManager.update(viewDescriptors, updates);
};
}
export const updatePropsJestWrapper = (viewDescriptors, updates, maybeViewRef, animatedStyle, adapters) => {
adapters.forEach(adapter => {
adapter(updates);
});
animatedStyle.current.value = {
...animatedStyle.current.value,
...updates
};
updateProps(viewDescriptors, updates, maybeViewRef);
};
export default updateProps;
const createUpdatePropsManager = global._IS_FABRIC ? () => {
'worklet';
// Fabric
const operations = [];
return {
update(viewDescriptors, updates) {
viewDescriptors.value.forEach(viewDescriptor => {
operations.push({
shadowNodeWrapper: viewDescriptor.shadowNodeWrapper,
updates
});
if (operations.length === 1) {
queueMicrotask(this.flush);
}
});
},
flush() {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
_updatePropsFabric(operations);
operations.length = 0;
}
};
} : () => {
'worklet';
// Paper
const operations = [];
return {
update(viewDescriptors, updates) {
viewDescriptors.value.forEach(viewDescriptor => {
operations.push({
tag: viewDescriptor.tag,
name: viewDescriptor.name || 'RCTView',
updates
});
if (operations.length === 1) {
queueMicrotask(this.flush);
}
});
},
flush() {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
_updatePropsPaper(operations);
operations.length = 0;
}
};
};
runOnUIImmediately(() => {
'worklet';
global.UpdatePropsManager = createUpdatePropsManager();
})();
//# sourceMappingURL=UpdateProps.js.map