Skip to content

Commit c697e21

Browse files
committed
clang format setup like vision camera
1 parent 5f451f2 commit c697e21

36 files changed

+847
-1262
lines changed

.github/workflows/validate-cpp.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ on:
55
branches:
66
- main
77
paths:
8-
- '.github/workflows/validate-cpp.yml'
9-
- 'package/cpp/**'
10-
- 'package/android/src/main/cpp/**'
11-
- 'package/ios/**'
8+
- ".github/workflows/validate-cpp.yml"
9+
- "package/cpp/**"
10+
- "package/android/src/main/cpp/**"
11+
- "package/ios/**"
1212
pull_request:
1313
paths:
14-
- '.github/workflows/validate-cpp.yml'
15-
- 'package/cpp/**'
16-
- 'package/android/src/main/cpp/**'
17-
- 'package/ios/**'
14+
- ".github/workflows/validate-cpp.yml"
15+
- "package/cpp/**"
16+
- "package/android/src/main/cpp/**"
17+
- "package/ios/**"
1818

1919
jobs:
2020
lint:
@@ -23,14 +23,14 @@ jobs:
2323
strategy:
2424
matrix:
2525
path:
26-
- 'package/cpp'
27-
- 'package/android/src/main/cpp'
28-
- 'package/ios'
26+
- "package/cpp"
27+
- "package/android/src/main/cpp"
28+
- "package/ios"
2929
steps:
3030
- uses: actions/checkout@v4
3131
- name: Run clang-format style check
32-
uses: jidicula/clang-format-action@v4.11.0
32+
uses: mrousavy/clang-format-action@v1
3333
with:
34-
clang-format-version: '16'
34+
clang-format-version: "16"
3535
check-path: ${{ matrix.path }}
36-
36+
clang-format-style-path: package/.clang-format

package/.clang-format

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Config for clang-format version 16
2+
3+
# Standard
4+
BasedOnStyle: llvm
5+
Standard: c++14
6+
7+
# Indentation
8+
IndentWidth: 2
9+
ColumnLimit: 140
10+
11+
# Includes
12+
SortIncludes: CaseSensitive
13+
SortUsingDeclarations: true
14+
15+
# Pointer and reference alignment
16+
PointerAlignment: Left
17+
ReferenceAlignment: Left
18+
ReflowComments: true
19+
20+
# Line breaking options
21+
BreakBeforeBraces: Attach
22+
BreakConstructorInitializers: BeforeColon
23+
AllowShortFunctionsOnASingleLine: Empty
24+
IndentCaseLabels: true
25+
NamespaceIndentation: Inner

package/android/src/main/cpp/JNIOnLoad.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
using namespace RNWorklet;
88

9-
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
9+
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
1010
return facebook::jni::initialize(vm, [] { JWorklets::registerNatives(); });
1111
}

package/android/src/main/cpp/JWorklets.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ namespace RNWorklet {
88

99
JWorklets::JWorklets() = default;
1010

11-
jni::local_ref<JWorklets::jhybriddata>
12-
JWorklets::initHybrid(jni::alias_ref<JWorklets::jhybridobject>) {
11+
jni::local_ref<JWorklets::jhybriddata> JWorklets::initHybrid(jni::alias_ref<JWorklets::jhybridobject>) {
1312
return makeCxxInstance();
1413
}
1514

16-
void JWorklets::install(
17-
jlong runtimePointer,
18-
jni::alias_ref<react::CallInvokerHolder::javaobject> callInvokerHolder) {
19-
auto runtime = reinterpret_cast<jsi::Runtime *>(runtimePointer);
15+
void JWorklets::install(jlong runtimePointer, jni::alias_ref<react::CallInvokerHolder::javaobject> callInvokerHolder) {
16+
auto runtime = reinterpret_cast<jsi::Runtime*>(runtimePointer);
2017
if (runtime == nullptr) {
2118
throw std::invalid_argument("jsi::Runtime was null!");
2219
}
@@ -33,8 +30,7 @@ void JWorklets::install(
3330
}
3431

3532
void JWorklets::registerNatives() {
36-
registerHybrid({makeNativeMethod("initHybrid", JWorklets::initHybrid),
37-
makeNativeMethod("install", JWorklets::install)});
33+
registerHybrid({makeNativeMethod("initHybrid", JWorklets::initHybrid), makeNativeMethod("install", JWorklets::install)});
3834
}
3935

4036
} // namespace RNWorklet

package/android/src/main/cpp/JWorklets.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ class JWorklets final : public jni::HybridClass<JWorklets> {
1818

1919
private:
2020
// JNI Methods
21-
static jni::local_ref<JWorklets::jhybriddata>
22-
initHybrid(jni::alias_ref<jhybridobject> javaThis);
23-
void install(
24-
jlong runtimePointer,
25-
jni::alias_ref<react::CallInvokerHolder::javaobject> callInvokerHolder);
21+
static jni::local_ref<JWorklets::jhybriddata> initHybrid(jni::alias_ref<jhybridobject> javaThis);
22+
void install(jlong runtimePointer, jni::alias_ref<react::CallInvokerHolder::javaobject> callInvokerHolder);
2623

2724
private:
2825
static auto constexpr TAG = "Worklets";

package/cpp/WKTJsiBaseDecorator.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class JsiBaseDecorator {
1111
/**
1212
Initializes the decorator on the JS thread with the JS runtime
1313
*/
14-
virtual void initialize(jsi::Runtime &runtime) {}
14+
virtual void initialize(jsi::Runtime& runtime) {}
1515

1616
/**
1717
Called on the context's worklet thread, the runtime is the worklet runtime
1818
*/
19-
virtual void decorateRuntime(jsi::Runtime &runtime) = 0;
19+
virtual void decorateRuntime(jsi::Runtime& runtime) = 0;
2020
virtual ~JsiBaseDecorator() {}
2121
};
2222
} // namespace RNWorklet

package/cpp/WKTJsiDispatcher.h

+19-28
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ class JsiDispatcher {
2626
* @return A new dispatch function for running the provided function with
2727
* error handling
2828
*/
29-
static std::function<void()> createDispatcher(
30-
jsi::Runtime &runtime, std::shared_ptr<JsiWrapper> thisValuePtr,
31-
const jsi::HostFunctionType &functionPtr,
32-
const std::function<void(std::shared_ptr<JsiWrapper>)> onSuccess,
33-
const std::function<void(const char *)> onError) {
29+
static std::function<void()> createDispatcher(jsi::Runtime& runtime, std::shared_ptr<JsiWrapper> thisValuePtr,
30+
const jsi::HostFunctionType& functionPtr,
31+
const std::function<void(std::shared_ptr<JsiWrapper>)> onSuccess,
32+
const std::function<void(const char*)> onError) {
3433
std::vector<std::shared_ptr<JsiWrapper>> emptyArgs;
35-
return createDispatcher(runtime, thisValuePtr, functionPtr, emptyArgs,
36-
onSuccess, onError);
34+
return createDispatcher(runtime, thisValuePtr, functionPtr, emptyArgs, onSuccess, onError);
3735
}
3836

3937
/**
@@ -48,38 +46,31 @@ class JsiDispatcher {
4846
* @return A new dispatch function for running the provided function with
4947
* error handling
5048
*/
51-
static std::function<void()> createDispatcher(
52-
jsi::Runtime &runtime, std::shared_ptr<JsiWrapper> thisValuePtr,
53-
const jsi::HostFunctionType &functionPtr,
54-
const std::vector<std::shared_ptr<JsiWrapper>> &arguments,
55-
const std::function<void(std::shared_ptr<JsiWrapper>)> onSuccess,
56-
const std::function<void(const char *)> onError) {
49+
static std::function<void()> createDispatcher(jsi::Runtime& runtime, std::shared_ptr<JsiWrapper> thisValuePtr,
50+
const jsi::HostFunctionType& functionPtr,
51+
const std::vector<std::shared_ptr<JsiWrapper>>& arguments,
52+
const std::function<void(std::shared_ptr<JsiWrapper>)> onSuccess,
53+
const std::function<void(const char*)> onError) {
5754

5855
// Set up the callback to run on the correct runtime thread
59-
return [&runtime, arguments, thisValuePtr, functionPtr, onSuccess,
60-
onError]() {
56+
return [&runtime, arguments, thisValuePtr, functionPtr, onSuccess, onError]() {
6157
try {
6258
// Define return value
6359
jsi::Value retVal = jsi::Value::undefined();
6460

6561
// Arguments
66-
jsi::Value *args = new jsi::Value[arguments.size()];
62+
jsi::Value* args = new jsi::Value[arguments.size()];
6763
for (int i = 0; i < arguments.size(); ++i) {
6864
args[i] = JsiWrapper::unwrap(runtime, arguments[i]);
6965
}
7066

7167
// Call with this or not?
72-
if (thisValuePtr != nullptr &&
73-
thisValuePtr->getType() != JsiWrapperType::Null &&
68+
if (thisValuePtr != nullptr && thisValuePtr->getType() != JsiWrapperType::Null &&
7469
thisValuePtr->getType() != JsiWrapperType::Undefined) {
75-
retVal = functionPtr(
76-
runtime,
77-
JsiWrapper::unwrap(runtime, thisValuePtr).asObject(runtime),
78-
static_cast<const jsi::Value *>(args), arguments.size());
79-
} else {
80-
retVal = functionPtr(runtime, nullptr,
81-
static_cast<const jsi::Value *>(args),
70+
retVal = functionPtr(runtime, JsiWrapper::unwrap(runtime, thisValuePtr).asObject(runtime), static_cast<const jsi::Value*>(args),
8271
arguments.size());
72+
} else {
73+
retVal = functionPtr(runtime, nullptr, static_cast<const jsi::Value*>(args), arguments.size());
8374
}
8475

8576
delete[] args;
@@ -88,13 +79,13 @@ class JsiDispatcher {
8879
if (onSuccess != nullptr) {
8980
onSuccess(JsiWrapper::wrap(runtime, retVal));
9081
}
91-
} catch (const jsi::JSError &err) {
82+
} catch (const jsi::JSError& err) {
9283
if (onError != nullptr)
9384
onError(err.getMessage().c_str());
94-
} catch (const std::exception &err) {
85+
} catch (const std::exception& err) {
9586
if (onError != nullptr)
9687
onError(err.what());
97-
} catch (const std::runtime_error &err) {
88+
} catch (const std::runtime_error& err) {
9889
if (onError != nullptr)
9990
onError(err.what());
10091
} catch (...) {

0 commit comments

Comments
 (0)