Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandra Cynk authored and Aleksandra Cynk committed Jan 16, 2024
2 parents 273ac09 + c39f904 commit dc8bf2c
Show file tree
Hide file tree
Showing 198 changed files with 5,198 additions and 5,895 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ module.exports = {
},
rules: {
curly: 'error',
'no-case-declarations': 'error',
'@typescript-eslint/no-shadow': 'error',
'import/no-unresolved': 'error',
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'react/jsx-uses-vars': 'error',
'react/jsx-uses-react': 'error',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'off', // TODO consider enabling this (currently it reports styles defined at the bottom of the file)
'@typescript-eslint/ban-ts-comment': [
'error',
{
Expand All @@ -60,5 +61,6 @@ module.exports = {
{ fixMixedExportsWithInlineTypeSpecifier: false },
],
'tsdoc/syntax': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
},
};
5 changes: 2 additions & 3 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Bug report
description: Report an issue with Reanimated here.
labels: 'Needs review'
body:
- type: markdown
attributes:
Expand Down Expand Up @@ -57,7 +56,7 @@ body:
attributes:
label: Reanimated version
description: What version of react-native-reanimated are you using?
placeholder: 2.9.0
placeholder: 3.6.1
validations:
required: true

Expand All @@ -66,7 +65,7 @@ body:
attributes:
label: React Native version
description: What version of react-native are you using?
placeholder: 0.69.0
placeholder: 0.73.1
validations:
required: true

Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/build-monorepo-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
group: ${{ inputs.concurrency_group }}
cancel-in-progress: true
steps:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- name: Create directories
run: mkdir -p monorepo/packages
- name: Create RootApp
Expand Down Expand Up @@ -63,11 +68,11 @@ jobs:
- name: Build iOS app RootApp
if: ${{ inputs.platform == 'iOS' }}
working-directory: monorepo/RootApp
run: yarn react-native run-ios --simulator='iPhone 14'
run: yarn react-native run-ios --simulator='iPhone 14' --no-packager
- name: Build iOS app PackageApp
if: ${{ inputs.platform == 'iOS' }}
working-directory: monorepo/packages/PackageApp
run: yarn react-native run-ios --simulator='iPhone 14'
run: yarn react-native run-ios --simulator='iPhone 14' --no-packager

- name: Build Android RootApp
if: ${{ inputs.platform == 'Android' }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-on-windows-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
group: build-on-windows-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'
- name: Create React Native App
run: npx react-native init App
- name: Install Reanimated
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-static-framework-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
run: export USE_FRAMEWORKS=static NO_FLIPPER=1 RCT_NEW_ARCH_ENABLED=1 && pod install
- name: Build app
working-directory: app
run: npx react-native run-ios
run: npx react-native run-ios --no-packager
18 changes: 18 additions & 0 deletions .github/workflows/format-pull-request-description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Format Pull Request Description

on:
pull_request:
types:
- opened

jobs:
format-pull-request-description:
runs-on: ubuntu-latest
steps:
- name: Update PR Description
uses: software-mansion-labs/pr-description@main
with:
content: ""
regex: "<!-- .* -->\n"
regexFlags: img
token: ${{ secrets.GITHUB_TOKEN }}
12 changes: 12 additions & 0 deletions Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ void LayoutAnimationsManager::configureAnimation(
}
}

void LayoutAnimationsManager::configureAnimationBatch(
std::vector<LayoutAnimationConfig> &layoutAnimationsBatch) {
auto lock = std::unique_lock<std::mutex>(animationsMutex_);
for (auto [tag, type, config] : layoutAnimationsBatch) {
if (config == nullptr) {
getConfigsForType(type).erase(tag);
} else {
getConfigsForType(type)[tag] = config;
}
}
}

void LayoutAnimationsManager::setShouldAnimateExiting(int tag, bool value) {
auto lock = std::unique_lock<std::mutex>(animationsMutex_);
shouldAnimateExitingForTag_[tag] = value;
Expand Down
8 changes: 8 additions & 0 deletions Common/cpp/LayoutAnimations/LayoutAnimationsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ namespace reanimated {

using namespace facebook;

struct LayoutAnimationConfig {
int tag;
LayoutAnimationType type;
std::shared_ptr<Shareable> config;
};

class LayoutAnimationsManager {
public:
explicit LayoutAnimationsManager(const std::shared_ptr<JSLogger> &jsLogger)
Expand All @@ -27,6 +33,8 @@ class LayoutAnimationsManager {
LayoutAnimationType type,
const std::string &sharedTransitionTag,
std::shared_ptr<Shareable> config);
void configureAnimationBatch(
std::vector<LayoutAnimationConfig> &layoutAnimationsBatch);
void setShouldAnimateExiting(int tag, bool value);
bool shouldAnimateExiting(int tag, bool shouldAnimate);
bool hasLayoutAnimation(int tag, LayoutAnimationType type);
Expand Down
47 changes: 36 additions & 11 deletions Common/cpp/NativeModules/NativeReanimatedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ NativeReanimatedModule::NativeReanimatedModule(
const std::shared_ptr<CallInvoker> &jsInvoker,
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<UIScheduler> &uiScheduler,
const PlatformDepMethodsHolder &platformDepMethodsHolder)
const PlatformDepMethodsHolder &platformDepMethodsHolder,
const std::string &valueUnpackerCode)
: NativeReanimatedModuleSpec(jsInvoker),
jsQueue_(jsQueue),
jsScheduler_(std::make_shared<JSScheduler>(rnRuntime, jsInvoker)),
Expand All @@ -58,7 +59,9 @@ NativeReanimatedModule::NativeReanimatedModule(
rnRuntime,
jsQueue,
jsScheduler_,
"Reanimated UI runtime")),
"Reanimated UI runtime",
valueUnpackerCode)),
valueUnpackerCode_(valueUnpackerCode),
eventHandlerRegistry_(std::make_unique<EventHandlerRegistry>()),
requestRender_(platformDepMethodsHolder.requestRender),
onRenderCallback_([this](const double timestampMs) {
Expand Down Expand Up @@ -132,13 +135,6 @@ NativeReanimatedModule::NativeReanimatedModule(
platformDepMethodsHolder.maybeFlushUIUpdatesQueueFunction);
}

void NativeReanimatedModule::installValueUnpacker(
jsi::Runtime &rt,
const jsi::Value &valueUnpackerCode) {
valueUnpackerCode_ = valueUnpackerCode.asString(rt).utf8(rt);
uiWorkletRuntime_->installValueUnpacker(valueUnpackerCode_);
}

NativeReanimatedModule::~NativeReanimatedModule() {
// event handler registry and frame callbacks store some JSI values from UI
// runtime, so they have to go away before we tear down the runtime
Expand Down Expand Up @@ -170,8 +166,11 @@ jsi::Value NativeReanimatedModule::createWorkletRuntime(
const jsi::Value &name,
const jsi::Value &initializer) {
auto workletRuntime = std::make_shared<WorkletRuntime>(
rt, jsQueue_, jsScheduler_, name.asString(rt).utf8(rt));
workletRuntime->installValueUnpacker(valueUnpackerCode_);
rt,
jsQueue_,
jsScheduler_,
name.asString(rt).utf8(rt),
valueUnpackerCode_);
auto initializerShareable = extractShareableOrThrow<ShareableWorklet>(
rt, initializer, "[Reanimated] Initializer must be a worklet.");
workletRuntime->runGuarded(initializerShareable);
Expand Down Expand Up @@ -324,6 +323,32 @@ jsi::Value NativeReanimatedModule::configureLayoutAnimation(
return jsi::Value::undefined();
}

jsi::Value NativeReanimatedModule::configureLayoutAnimationBatch(
jsi::Runtime &rt,
const jsi::Value &layoutAnimationsBatch) {
auto array = layoutAnimationsBatch.asObject(rt).asArray(rt);
size_t length = array.size(rt);
std::vector<LayoutAnimationConfig> batch(length);
for (int i = 0; i < length; i++) {
auto item = array.getValueAtIndex(rt, i).asObject(rt);
auto &batchItem = batch[i];
batchItem.tag = item.getProperty(rt, "viewTag").asNumber();
batchItem.type = static_cast<LayoutAnimationType>(
item.getProperty(rt, "type").asNumber());
auto config = item.getProperty(rt, "config");
if (config.isUndefined()) {
batchItem.config = nullptr;
} else {
batchItem.config = extractShareableOrThrow<ShareableObject>(
rt,
config,
"[Reanimated] Layout animation config must be an object.");
}
}
layoutAnimationsManager_.configureAnimationBatch(batch);
return jsi::Value::undefined();
}

void NativeReanimatedModule::setShouldAnimateExiting(
jsi::Runtime &rt,
const jsi::Value &viewTag,
Expand Down
10 changes: 5 additions & 5 deletions Common/cpp/NativeModules/NativeReanimatedModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
const std::shared_ptr<CallInvoker> &jsInvoker,
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<UIScheduler> &uiScheduler,
const PlatformDepMethodsHolder &platformDepMethodsHolder);
const PlatformDepMethodsHolder &platformDepMethodsHolder,
const std::string &valueUnpackerCode);

~NativeReanimatedModule();

void installValueUnpacker(
jsi::Runtime &rt,
const jsi::Value &valueUnpackerCode) override;

jsi::Value makeShareableClone(
jsi::Runtime &rt,
const jsi::Value &value,
Expand Down Expand Up @@ -98,6 +95,9 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
const jsi::Value &type,
const jsi::Value &sharedTransitionTag,
const jsi::Value &config) override;
jsi::Value configureLayoutAnimationBatch(
jsi::Runtime &rt,
const jsi::Value &layoutAnimationsBatch) override;
void setShouldAnimateExiting(
jsi::Runtime &rt,
const jsi::Value &viewTag,
Expand Down
24 changes: 11 additions & 13 deletions Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@

namespace reanimated {

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

// SharedValue

static jsi::Value SPEC_PREFIX(makeShareableClone)(
Expand Down Expand Up @@ -185,6 +175,15 @@ static jsi::Value SPEC_PREFIX(configureLayoutAnimation)(
std::move(args[3]));
}

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

static jsi::Value SPEC_PREFIX(setShouldAnimateExiting)(
jsi::Runtime &rt,
TurboModule &turboModule,
Expand All @@ -198,9 +197,6 @@ static jsi::Value SPEC_PREFIX(setShouldAnimateExiting)(
NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(
std::shared_ptr<CallInvoker> jsInvoker)
: TurboModule("NativeReanimated", jsInvoker) {
methodMap_["installValueUnpacker"] =
MethodMetadata{1, SPEC_PREFIX(installValueUnpacker)};

methodMap_["makeShareableClone"] =
MethodMetadata{2, SPEC_PREFIX(makeShareableClone)};

Expand Down Expand Up @@ -234,6 +230,8 @@ NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(

methodMap_["configureLayoutAnimation"] =
MethodMetadata{4, SPEC_PREFIX(configureLayoutAnimation)};
methodMap_["configureLayoutAnimationBatch"] =
MethodMetadata{1, SPEC_PREFIX(configureLayoutAnimationBatch)};
methodMap_["setShouldAnimateExitingForTag"] =
MethodMetadata{2, SPEC_PREFIX(setShouldAnimateExiting)};
}
Expand Down
8 changes: 4 additions & 4 deletions Common/cpp/NativeModules/NativeReanimatedModuleSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ class JSI_EXPORT NativeReanimatedModuleSpec : public TurboModule {
explicit NativeReanimatedModuleSpec(std::shared_ptr<CallInvoker> jsInvoker);

public:
virtual void installValueUnpacker(
jsi::Runtime &rt,
const jsi::Value &valueUnpackerCode) = 0;

// SharedValue
virtual jsi::Value makeShareableClone(
jsi::Runtime &rt,
Expand Down Expand Up @@ -107,6 +103,10 @@ class JSI_EXPORT NativeReanimatedModuleSpec : public TurboModule {
const jsi::Value &sharedTransitionTag,
const jsi::Value &config) = 0;

virtual jsi::Value configureLayoutAnimationBatch(
jsi::Runtime &rt,
const jsi::Value &layoutAnimationsBatch) = 0;

virtual void setShouldAnimateExiting(
jsi::Runtime &rt,
const jsi::Value &viewTag,
Expand Down
1 change: 1 addition & 0 deletions Common/cpp/ReanimatedRuntime/RNRuntimeDecorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void RNRuntimeDecorator::decorate(
#ifndef NDEBUG
checkJSVersion(rnRuntime, nativeReanimatedModule->getJSLogger());
#endif // NDEBUG
injectReanimatedCppVersion(rnRuntime);

rnRuntime.global().setProperty(
rnRuntime, "_REANIMATED_IS_REDUCED_MOTION", isReducedMotion);
Expand Down
14 changes: 6 additions & 8 deletions Common/cpp/ReanimatedRuntime/WorkletRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ WorkletRuntime::WorkletRuntime(
jsi::Runtime &rnRuntime,
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<JSScheduler> &jsScheduler,
const std::string &name)
const std::string &name,
const std::string &valueUnpackerCode)
: runtime_(ReanimatedRuntime::make(rnRuntime, jsQueue, name)), name_(name) {
jsi::Runtime &rt = *runtime_;
WorkletRuntimeCollector::install(rt);
WorkletRuntimeDecorator::decorate(rt, name, jsScheduler);
}

void WorkletRuntime::installValueUnpacker(
const std::string &valueUnpackerCode) {
jsi::Runtime &rt = *runtime_;
auto codeBuffer = std::make_shared<const jsi::StringBuffer>(
"(" + valueUnpackerCode + "\n)");
auto valueUnpacker = rt.evaluateJavaScript(codeBuffer, "installValueUnpacker")
.asObject(rt)
.asFunction(rt);
auto valueUnpacker =
rt.evaluateJavaScript(codeBuffer, "WorkletRuntime::WorkletRuntime")
.asObject(rt)
.asFunction(rt);
rt.global().setProperty(rt, "__valueUnpacker", valueUnpacker);
}

Expand Down
5 changes: 2 additions & 3 deletions Common/cpp/ReanimatedRuntime/WorkletRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ class WorkletRuntime : public jsi::HostObject,
jsi::Runtime &rnRuntime,
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<JSScheduler> &jsScheduler,
const std::string &name);

void installValueUnpacker(const std::string &valueUnpackerCode);
const std::string &name,
const std::string &valueUnpackerCode);

jsi::Runtime &getJSIRuntime() const {
return *runtime_;
Expand Down
Loading

0 comments on commit dc8bf2c

Please sign in to comment.