Skip to content

Commit

Permalink
Merge branch 'main' into acynk/style-identity-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
Latropos authored Dec 11, 2023
2 parents be04e0f + ec9d645 commit 273ac09
Show file tree
Hide file tree
Showing 212 changed files with 6,002 additions and 2,608 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
.eslintrc.js
scripts/*.js
docs/*
plugin/*
eslintrc.js
jest.config.js
11 changes: 10 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:import/typescript',
'plugin:react-hooks/recommended',
],
plugins: [
'react',
'react-native',
'import',
'jest',
'@typescript-eslint',
'eslint-plugin-tsdoc',
],
plugins: ['react', 'react-native', 'import', 'jest', '@typescript-eslint'],
env: {
'react-native/react-native': true,
'jest/globals': true,
Expand Down Expand Up @@ -51,5 +59,6 @@ module.exports = {
'error',
{ fixMixedExportsWithInlineTypeSpecifier: false },
],
'tsdoc/syntax': 'error',
},
};
11 changes: 7 additions & 4 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ body:
label: Workflow
description: How is your application managed?
options:
- React Native
- React Native
- Expo Go
- Expo Dev Client

Expand All @@ -123,10 +123,13 @@ body:
id: build-type
attributes:
label: Build type
description: What mode your application is running?
description: What is the build configuration/variant of your native app and JavaScript bundle mode?
options:
- Debug mode
- Release mode
- Debug app & dev bundle
- Release app & production bundle
- Debug app & production bundle
- Release app & dev bundle
- Other (please specify)

- type: dropdown
id: emulator
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-monorepo-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
run: mkdir -p monorepo/packages
- name: Create RootApp
working-directory: monorepo
run: npx react-native@next init RootApp --skip-install ${{ env.REACT_NATIVE_TEMPLATE }}
run: npx react-native init RootApp --skip-install ${{ env.REACT_NATIVE_TEMPLATE }}
- name: Create PackageApp
working-directory: monorepo/packages
run: npx react-native@next init PackageApp --skip-install ${{ env.REACT_NATIVE_TEMPLATE }}
run: npx react-native init PackageApp --skip-install ${{ env.REACT_NATIVE_TEMPLATE }}
- name: Setup monorepo
working-directory: monorepo
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/check-expo-dev-client-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
paths:
- .github/workflows/check-expo-dev-client-nightly.yml
schedule:
- cron: '37 19 * * *'
- cron: '0 0 * * *' # after publishing new nightly version on NPM
workflow_dispatch:

env:
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
run: npx expo prebuild
- name: Install Reanimated
working-directory: app
run: npm install github:software-mansion/react-native-reanimated#${{ github.ref }}
run: npm install react-native-reanimated@nightly
- name: Set Fabric
if: ${{ matrix.react-native-architecture == 'Fabric' }}
run: node ${{ env.SCRIPT_PATH }} setupFabricIOS
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
run: npx expo prebuild
- name: Install Reanimated
working-directory: app
run: npm install github:software-mansion/react-native-reanimated
run: npm install react-native-reanimated@nightly
- name: Set Fabric
if: ${{ matrix.react-native-architecture == 'Fabric' }}
run: node ${{ env.SCRIPT_PATH }} setupFabricAndroid
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ios-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
- .github/workflows/ios-build.yml
- RNReanimated.podspec
- scripts/reanimated_utils.rb
- ios/**
- apple/**
- Common/**
- Example/package.json
- Example/ios/**
Expand Down
24 changes: 17 additions & 7 deletions .github/workflows/macos-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@ name: Test macOS build
on:
pull_request:
paths:
- '.github/workflows/macos-build.yml'
- 'RNReanimated.podspec'
- 'apple/**'
- 'Common/**'
- 'MacOSExample/package.json'
- 'MacOSExample/ios/**'
- 'MacOSExample/macos/**'
- .github/workflows/macos-build.yml
- RNReanimated.podspec
- scripts/reanimated_utils.rb
- apple/**
- Common/**
- MacOSExample/package.json
- MacOSExample/ios/**
- MacOSExample/macos/**
merge_group:
branches:
- main
push:
branches:
- main
paths:
- .github/workflows/macos-build.yml
- RNReanimated.podspec
- scripts/reanimated_utils.rb
- apple/**
- Common/**
- MacOSExample/package.json
- MacOSExample/ios/**
- MacOSExample/macos/**

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/static-root-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ jobs:
run: yarn find-unused-code:js
- name: Find circular dependencies
run: yarn circular_dependency_check
- name: Check use strict
run: yarn use_strict_check
- name: Run jest unit tests
run: yarn test:unit
2 changes: 1 addition & 1 deletion .github/workflows/tvos-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
paths:
- '.github/workflows/tvos-build.yml'
- 'RNReanimated.podspec'
- 'ios/**'
- 'apple/**'
- 'Common/**'
- 'TVOSExample/package.json'
- 'TVOSExample/ios/**'
Expand Down
9 changes: 2 additions & 7 deletions Common/cpp/LayoutAnimations/LayoutAnimationsManager.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#pragma once

#include "JSLogger.h"
#include "LayoutAnimationType.h"
#include "Shareables.h"

#ifndef NDEBUG
#include "JSLogger.h"
#endif

#include <jsi/jsi.h>
#include <stdio.h>
#include <functional>
Expand All @@ -23,10 +20,8 @@ using namespace facebook;

class LayoutAnimationsManager {
public:
#ifndef NDEBUG
explicit LayoutAnimationsManager(const std::shared_ptr<JSLogger> &jsLogger)
: jsLogger_(jsLogger) {}
#endif
void configureAnimation(
int tag,
LayoutAnimationType type,
Expand Down Expand Up @@ -54,8 +49,8 @@ class LayoutAnimationsManager {
std::unordered_map<int, std::shared_ptr<Shareable>> &getConfigsForType(
LayoutAnimationType type);

#ifndef NDEBUG
std::shared_ptr<JSLogger> jsLogger_;
#ifndef NDEBUG
// This set's function is to detect duplicate sharedTags on a single screen
// it contains strings in form: "reactScreenTag:sharedTag"
std::unordered_set<std::string> screenSharedTagSet_;
Expand Down
71 changes: 61 additions & 10 deletions Common/cpp/NativeModules/NativeReanimatedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "ShadowTreeCloner.h"
#endif

#include "AsyncQueue.h"
#include "CollectionUtils.h"
#include "EventHandlerRegistry.h"
#include "FeaturesConfig.h"
#include "JSScheduler.h"
Expand Down Expand Up @@ -64,9 +66,8 @@ NativeReanimatedModule::NativeReanimatedModule(
onRender(timestampMs);
}),
animatedSensorModule_(platformDepMethodsHolder),
#ifndef NDEBUG
layoutAnimationsManager_(std::make_shared<JSLogger>(jsScheduler_)),
#endif
jsLogger_(std::make_shared<JSLogger>(jsScheduler_)),
layoutAnimationsManager_(jsLogger_),
#ifdef RCT_NEW_ARCH_ENABLED
synchronouslyUpdateUIPropsFunction_(
platformDepMethodsHolder.synchronouslyUpdateUIPropsFunction),
Expand Down Expand Up @@ -177,6 +178,14 @@ jsi::Value NativeReanimatedModule::createWorkletRuntime(
return jsi::Object::createFromHostObject(rt, workletRuntime);
}

jsi::Value NativeReanimatedModule::scheduleOnRuntime(
jsi::Runtime &rt,
const jsi::Value &workletRuntimeValue,
const jsi::Value &shareableWorkletValue) {
reanimated::scheduleOnRuntime(rt, workletRuntimeValue, shareableWorkletValue);
return jsi::Value::undefined();
}

jsi::Value NativeReanimatedModule::makeSynchronizedDataHolder(
jsi::Runtime &rt,
const jsi::Value &initialShareable) {
Expand All @@ -195,9 +204,7 @@ void NativeReanimatedModule::updateDataSynchronously(
jsi::Value NativeReanimatedModule::getDataSynchronously(
jsi::Runtime &rt,
const jsi::Value &synchronizedDataHolderRef) {
auto dataHolder = extractShareableOrThrow<ShareableSynchronizedDataHolder>(
rt, synchronizedDataHolderRef);
return dataHolder->get(rt);
return reanimated::getDataSynchronously(rt, synchronizedDataHolderRef);
}

jsi::Value NativeReanimatedModule::makeShareableClone(
Expand Down Expand Up @@ -282,11 +289,16 @@ jsi::Value NativeReanimatedModule::configureProps(
const jsi::Value &uiProps,
const jsi::Value &nativeProps) {
#ifdef RCT_NEW_ARCH_ENABLED
(void)uiProps; // unused variable on Fabric
jsi::Array array = nativeProps.asObject(rt).asArray(rt);
for (size_t i = 0; i < array.size(rt); ++i) {
std::string name = array.getValueAtIndex(rt, i).asString(rt).utf8(rt);
auto uiPropsArray = uiProps.asObject(rt).asArray(rt);
for (size_t i = 0; i < uiPropsArray.size(rt); ++i) {
auto name = uiPropsArray.getValueAtIndex(rt, i).asString(rt).utf8(rt);
animatablePropNames_.insert(name);
}
auto nativePropsArray = nativeProps.asObject(rt).asArray(rt);
for (size_t i = 0; i < nativePropsArray.size(rt); ++i) {
auto name = nativePropsArray.getValueAtIndex(rt, i).asString(rt).utf8(rt);
nativePropNames_.insert(name);
animatablePropNames_.insert(name);
}
#else
configurePropsPlatformFunction_(rt, uiProps, nativeProps);
Expand Down Expand Up @@ -393,6 +405,29 @@ bool NativeReanimatedModule::isThereAnyLayoutProp(
}
return false;
}

jsi::Value NativeReanimatedModule::filterNonAnimatableProps(
jsi::Runtime &rt,
const jsi::Value &props) {
jsi::Object nonAnimatableProps(rt);
bool hasAnyNonAnimatableProp = false;
const jsi::Object &propsObject = props.asObject(rt);
const jsi::Array &propNames = propsObject.getPropertyNames(rt);
for (size_t i = 0; i < propNames.size(rt); ++i) {
const std::string &propName =
propNames.getValueAtIndex(rt, i).asString(rt).utf8(rt);
if (!collection::contains(animatablePropNames_, propName)) {
hasAnyNonAnimatableProp = true;
const auto &propNameStr = propName.c_str();
const jsi::Value &propValue = propsObject.getProperty(rt, propNameStr);
nonAnimatableProps.setProperty(rt, propNameStr, propValue);
}
}
if (!hasAnyNonAnimatableProp) {
return jsi::Value::undefined();
}
return nonAnimatableProps;
}
#endif // RCT_NEW_ARCH_ENABLED

bool NativeReanimatedModule::handleEvent(
Expand Down Expand Up @@ -494,6 +529,22 @@ void NativeReanimatedModule::performOperations() {
}
}

for (const auto &[shadowNode, props] : copiedOperationsQueue) {
const jsi::Value &nonAnimatableProps = filterNonAnimatableProps(rt, *props);
if (nonAnimatableProps.isUndefined()) {
continue;
}
Tag viewTag = shadowNode->getTag();
jsi::Value maybeJSPropsUpdater =
rt.global().getProperty(rt, "updateJSProps");
assert(
maybeJSPropsUpdater.isObject() &&
"[Reanimated] `updateJSProps` not found");
jsi::Function jsPropsUpdater =
maybeJSPropsUpdater.asObject(rt).asFunction(rt);
jsPropsUpdater.call(rt, viewTag, nonAnimatableProps);
}

bool hasLayoutUpdates = false;
for (const auto &[shadowNode, props] : copiedOperationsQueue) {
if (isThereAnyLayoutProp(rt, props->asObject(rt))) {
Expand Down
15 changes: 14 additions & 1 deletion Common/cpp/NativeModules/NativeReanimatedModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
jsi::Runtime &rt,
const jsi::Value &name,
const jsi::Value &initializer) override;
jsi::Value scheduleOnRuntime(
jsi::Runtime &rt,
const jsi::Value &workletRuntimeValue,
const jsi::Value &shareableWorkletValue) override;

jsi::Value registerEventHandler(
jsi::Runtime &rt,
Expand Down Expand Up @@ -113,6 +117,10 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
const jsi::Value &payload,
double currentTime);

inline std::shared_ptr<JSLogger> getJSLogger() const {
return jsLogger_;
}

#ifdef RCT_NEW_ARCH_ENABLED
bool handleRawEvent(const RawEvent &rawEvent, double currentTime);

Expand Down Expand Up @@ -164,6 +172,9 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {

#ifdef RCT_NEW_ARCH_ENABLED
bool isThereAnyLayoutProp(jsi::Runtime &rt, const jsi::Object &props);
jsi::Value filterNonAnimatableProps(
jsi::Runtime &rt,
const jsi::Value &props);
#endif // RCT_NEW_ARCH_ENABLED

const std::shared_ptr<MessageQueueThread> jsQueue_;
Expand All @@ -178,13 +189,15 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
volatile bool renderRequested_{false};
const std::function<void(const double)> onRenderCallback_;
AnimatedSensorModule animatedSensorModule_;
const std::shared_ptr<JSLogger> jsLogger_;
LayoutAnimationsManager layoutAnimationsManager_;

#ifdef RCT_NEW_ARCH_ENABLED
const SynchronouslyUpdateUIPropsFunction synchronouslyUpdateUIPropsFunction_;

std::unordered_set<std::string> nativePropNames_; // filled by configureProps

std::unordered_set<std::string>
animatablePropNames_; // filled by configureProps
std::shared_ptr<UIManager> uiManager_;

// After app reload, surfaceId on iOS is still 1 but on Android it's 11.
Expand Down
11 changes: 11 additions & 0 deletions Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ static jsi::Value SPEC_PREFIX(createWorkletRuntime)(
->createWorkletRuntime(rt, std::move(args[0]), std::move(args[1]));
}

static jsi::Value SPEC_PREFIX(scheduleOnRuntime)(
jsi::Runtime &rt,
TurboModule &turboModule,
const jsi::Value *args,
size_t) {
return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
->scheduleOnRuntime(rt, std::move(args[0]), std::move(args[1]));
}

static jsi::Value SPEC_PREFIX(registerEventHandler)(
jsi::Runtime &rt,
TurboModule &turboModule,
Expand Down Expand Up @@ -203,6 +212,8 @@ NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(
methodMap_["scheduleOnUI"] = MethodMetadata{1, SPEC_PREFIX(scheduleOnUI)};
methodMap_["createWorkletRuntime"] =
MethodMetadata{2, SPEC_PREFIX(createWorkletRuntime)};
methodMap_["scheduleOnRuntime"] =
MethodMetadata{2, SPEC_PREFIX(scheduleOnRuntime)};

methodMap_["registerEventHandler"] =
MethodMetadata{3, SPEC_PREFIX(registerEventHandler)};
Expand Down
Loading

0 comments on commit 273ac09

Please sign in to comment.