Skip to content

Commit

Permalink
Merge branch '@kwasow/bobFix' into @jpiasecki/types/nativemethods
Browse files Browse the repository at this point in the history
  • Loading branch information
j-piasecki committed Mar 1, 2023
2 parents a35f4a8 + 63566e5 commit a18f702
Show file tree
Hide file tree
Showing 655 changed files with 25,572 additions and 29,623 deletions.
53 changes: 5 additions & 48 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,9 @@
## Description
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. -->

<!--
Description and motivation for this PR.
## Summary

Include Fixes #<number> if this is fixing some issue.
<!-- Explain the motivation for this PR. Include "Fixes #<number>" if applicable. -->

Fixes # .
-->
## Test plan

## Changes

<!--
Please describe things you've changed here, make a **high level** overview, if change is simple you can omit this section.
For example:
- Added `foo` method which add bouncing animation
- Updated `about.md` docs
- Added caching in CI builds
-->

<!--
## Screenshots / GIFs
Here you can add screenshots / GIFs documenting your change.
You can add before / after section if you're changing some behavior.
### Before
### After
-->

## Test code and steps to reproduce

<!--
Please include code that can be used to test this change and short description how this example should work.
This snippet should be as minimal as possible and ready to be pasted into editor (don't exclude exports or remove "not important" parts of reproduction example)
-->

## Checklist

- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Added TS types tests
- [ ] Added unit / integration tests
- [ ] Updated documentation
- [ ] Ensured that CI passes
<!-- Provide a minimal but complete code snippet that can be used to test out this change along with instructions how to run it and a description of the expected behavior. -->
73 changes: 34 additions & 39 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ name: Test Android build
on:
pull_request:
paths:
- 'android/**'
- 'Common/**'
- 'FabricExample/package.json'
- 'Example/package.json'
- .github/workflows/android-build.yml
- android/**
- Common/**
- Example/package.json
- Example/android/**
- FabricExample/package.json
- FabricExample/android/**
push:
branches:
- main
Expand All @@ -16,49 +19,41 @@ jobs:
strategy:
matrix:
working-directory: [Example, FabricExample]
fail-fast: false
concurrency:
group: android-${{ matrix.working-directory }}-${{ github.ref }}
cancel-in-progress: true
steps:
- name: checkout
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Install NDK
uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r21d
- name: Set ANDROID_NDK
run: echo "ANDROID_NDK=$ANDROID_HOME/ndk-bundle" >> $GITHUB_ENV
- name: Accept licenses
run: /bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
- name: Use Node.js 14
uses: actions/setup-node@v2
- name: Check out Git repository
uses: actions/checkout@v3

- name: Setup Java 11
uses: actions/setup-java@v3
with:
node-version: 14
cache: 'yarn'
- name: Install root node dependencies
run: yarn
- name: Install example app node dependencies
working-directory: ${{ matrix.working-directory }}
run: yarn
- name: Cache hermes build
distribution: 'zulu'
java-version: 11

- name: Restore Reanimated node_modules from cache
uses: actions/cache@v3
env:
cache-name: cache-rn-hermes-engine
with:
path: ${{ matrix.working-directory }}/node_modules/react-native
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.working-directory }}-${{ hashFiles('**/react-native/package.json') }}
- name: Cache android libraries
path: node_modules
key: ${{ runner.os }}-android-node-modules-reanimated-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-android-node-modules-reanimated-

- name: Install Reanimated node_modules
run: yarn install --frozen-lockfile

- name: Restore app node_modules from cache
uses: actions/cache@v3
env:
cache-name: cache-rn
with:
path: ${{ matrix.working-directory }}/android/app/build/react-ndk
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.working-directory }}-${{ hashFiles('**/react-native/package.json') }}
path: ${{ matrix.working-directory }}/node_modules
key: ${{ runner.os }}-android-node-modules-${{ matrix.working-directory }}-${{ hashFiles(format('{0}/yarn.lock', matrix.working-directory)) }}
restore-keys: ${{ runner.os }}-android-node-modules-${{ matrix.working-directory }}-

- name: Install app node_modules
working-directory: ${{ matrix.working-directory }}
run: yarn install --frozen-lockfile

- name: Build app
working-directory: ${{ matrix.working-directory }}/android
run: ./gradlew assembleDebug --console=plain -PreactNativeArchitectures=arm64-v8a
run: ./gradlew assembleDebug --build-cache -PreactNativeArchitectures=arm64-v8a
4 changes: 2 additions & 2 deletions .github/workflows/build-monorepo-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
mkdir packages
- name: Create RootApp
working-directory: monorepo
run: npx react-native@next init RootApp ${{ env.REACT_NATIVE_TEMPLATE }}
run: npx react-native@next init RootApp --skip-install ${{ env.REACT_NATIVE_TEMPLATE }}
- name: Create PackageApp
working-directory: monorepo/packages
run: npx react-native@next init PackageApp ${{ env.REACT_NATIVE_TEMPLATE }}
run: npx react-native@next init PackageApp --skip-install ${{ env.REACT_NATIVE_TEMPLATE }}

- name: Install dependencies for RootApp
working-directory: monorepo/RootApp
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-monorepo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- .github/workflows/build-monorepo.yml
- .github/workflows/build-monorepo-action.yml
- RNReanimated.podspec
- scripts/reanimated_utils.rb
- android/build.gradle
push:
branches:
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/build-npm-package-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v1
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

- name: Set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'

- name: Install NDK
Expand All @@ -42,7 +43,7 @@ jobs:
- run: echo "PACKAGE_NAME=$(ls -l | egrep -o "react-native-reanimated-(.*)(=?\.tgz)")" >> $GITHUB_ENV

- name: Upload npm package
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ env.PACKAGE_NAME }}
path: '*.tgz'
Expand All @@ -53,7 +54,7 @@ jobs:

- name: Upload Android build folder
if: ${{ inputs.upload_binaries }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: android-build-output
path: android-build-output.zip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-v8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- main

env:
REACT_NATIVE_VERSION: "0.70.5"
REACT_NATIVE_VERSION: "0.71.3"

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ios-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
paths:
- .github/workflows/ios-build.yml
- RNReanimated.podspec
- scripts/reanimated_utils.rb
- ios/**
- Common/**
- Example/package.json
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static-root-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v2
- name: Use Node.js 14
- name: Use Node.js 16
uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16
cache: 'yarn'
- name: Install node dependencies
run: yarn
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/validate-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ on:
- main
paths:
- '.github/workflows/validate-cpp.yml'
- 'scripts/cpplint.sh'
- 'Common/cpp/**'
- 'ios/native/**'
- 'android/src/main/cpp/**'
pull_request:
paths:
- '.github/workflows/validate-cpp.yml'
- 'scripts/cpplint.sh'
- 'Common/cpp/**'
- 'ios/native/**'
- 'android/src/main/cpp/**'
Expand Down
97 changes: 55 additions & 42 deletions Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,71 @@
#include "AnimatedSensorModule.h"
#include "MutableValue.h"
#include "ValueWrapper.h"

#include <memory>
#include <utility>

#include "Shareables.h"

namespace reanimated {

AnimatedSensorModule::AnimatedSensorModule(
const PlatformDepMethodsHolder &platformDepMethodsHolder,
RuntimeManager *runtimeManager)
const PlatformDepMethodsHolder &platformDepMethodsHolder)
: platformRegisterSensorFunction_(platformDepMethodsHolder.registerSensor),
platformUnregisterSensorFunction_(
platformDepMethodsHolder.unregisterSensor),
runtimeManager_(runtimeManager) {}
platformDepMethodsHolder.unregisterSensor) {}

AnimatedSensorModule::~AnimatedSensorModule() {
// It is called during app reload because app reload doesn't call hooks
// unmounting
for (auto sensorId : sensorsIds_) {
platformUnregisterSensorFunction_(sensorId);
}
assert(sensorsIds_.empty());
}

jsi::Value AnimatedSensorModule::registerSensor(
jsi::Runtime &rt,
const jsi::Value &sensorType,
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
const jsi::Value &sensorTypeValue,
const jsi::Value &interval,
const jsi::Value &sensorDataContainer) {
std::shared_ptr<ShareableValue> sensorsData = ShareableValue::adapt(
rt, sensorDataContainer.getObject(rt), runtimeManager_);
auto &mutableObject =
ValueWrapper::asMutableValue(sensorsData->valueContainer);
const jsi::Value &iosReferenceFrame,
const jsi::Value &sensorDataHandler) {
SensorType sensorType = static_cast<SensorType>(sensorTypeValue.asNumber());

std::function<void(double[])> setter;
if (sensorType.asNumber() == SensorType::ROTATION_VECTOR) {
setter = [&, mutableObject](double newValues[]) {
jsi::Runtime &runtime = *runtimeManager_->runtime.get();
jsi::Object value(runtime);
value.setProperty(runtime, "qx", newValues[0]);
value.setProperty(runtime, "qy", newValues[1]);
value.setProperty(runtime, "qz", newValues[2]);
value.setProperty(runtime, "qw", newValues[3]);
value.setProperty(runtime, "yaw", newValues[4]);
value.setProperty(runtime, "pitch", newValues[5]);
value.setProperty(runtime, "roll", newValues[6]);
mutableObject->setValue(runtime, std::move(value));
};
} else {
setter = [&, mutableObject](double newValues[]) {
jsi::Runtime &runtime = *runtimeManager_->runtime.get();
jsi::Object value(runtime);
value.setProperty(runtime, "x", newValues[0]);
value.setProperty(runtime, "y", newValues[1]);
value.setProperty(runtime, "z", newValues[2]);
mutableObject->setValue(runtime, std::move(value));
};
}
auto shareableHandler = extractShareableOrThrow(rt, sensorDataHandler);

int sensorId = platformRegisterSensorFunction_(
sensorType.asNumber(), interval.asNumber(), setter);
sensorType,
interval.asNumber(),
iosReferenceFrame.asNumber(),
[sensorType,
shareableHandler,
weakRuntimeHelper = std::weak_ptr<JSRuntimeHelper>(runtimeHelper)](
double newValues[], int orientationDegrees) {
auto runtimeHelper = weakRuntimeHelper.lock();
if (runtimeHelper == nullptr || runtimeHelper->uiRuntimeDestroyed) {
return;
}

auto &rt = *runtimeHelper->uiRuntime();
auto handler = shareableHandler->getJSValue(rt);
if (sensorType == SensorType::ROTATION_VECTOR) {
jsi::Object value(rt);
// TODO: timestamp should be provided by the platform implementation
// such that the native side has a chance of providing a true event
// timestamp
value.setProperty(rt, "qx", newValues[0]);
value.setProperty(rt, "qy", newValues[1]);
value.setProperty(rt, "qz", newValues[2]);
value.setProperty(rt, "qw", newValues[3]);
value.setProperty(rt, "yaw", newValues[4]);
value.setProperty(rt, "pitch", newValues[5]);
value.setProperty(rt, "roll", newValues[6]);
value.setProperty(rt, "interfaceOrientation", orientationDegrees);
runtimeHelper->runOnUIGuarded(handler, value);
} else {
jsi::Object value(rt);
value.setProperty(rt, "x", newValues[0]);
value.setProperty(rt, "y", newValues[1]);
value.setProperty(rt, "z", newValues[2]);
value.setProperty(rt, "interfaceOrientation", orientationDegrees);
runtimeHelper->runOnUIGuarded(handler, value);
}
});
if (sensorId != -1) {
sensorsIds_.insert(sensorId);
}
Expand All @@ -72,4 +78,11 @@ void AnimatedSensorModule::unregisterSensor(const jsi::Value &sensorId) {
platformUnregisterSensorFunction_(sensorId.asNumber());
}

void AnimatedSensorModule::unregisterAllSensors() {
for (auto sensorId : sensorsIds_) {
platformUnregisterSensorFunction_(sensorId);
}
sensorsIds_.clear();
}

} // namespace reanimated
Loading

0 comments on commit a18f702

Please sign in to comment.