Skip to content

Commit

Permalink
Fix spotless config (#6349)
Browse files Browse the repository at this point in the history
## Summary

We've noticed that sometimes Java files are not properly formatted but
the CI is still green. The reason is that only `src/main/java/**/*.java`
was formatted but there are still `paper/`, `fabric/` and
`reactNativeVersionPatch/` directories that are not covered by this
glob.

This PR extends the coverage of spotless formatter as well as formats
the remaining files.

## Test plan
  • Loading branch information
tomekzaw authored Jul 30, 2024
1 parent 312280d commit f60dadd
Show file tree
Hide file tree
Showing 14 changed files with 392 additions and 405 deletions.
2 changes: 1 addition & 1 deletion packages/react-native-reanimated/android/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.diffplug.spotless'

spotless {
java {
target 'src/main/java/**/*.java'
target 'src/**/*.java'
googleJavaFormat()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.fabric.FabricUIManager;
import com.facebook.react.uimanager.UIManagerHelper;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.react.fabric.FabricUIManager;

class ReaCompatibility {
private FabricUIManager fabricUIManager;
private FabricUIManager fabricUIManager;

public ReaCompatibility(ReactApplicationContext reactApplicationContext) {
fabricUIManager = (FabricUIManager) UIManagerHelper.getUIManager(reactApplicationContext, UIManagerType.FABRIC);
}
public ReaCompatibility(ReactApplicationContext reactApplicationContext) {
fabricUIManager =
(FabricUIManager)
UIManagerHelper.getUIManager(reactApplicationContext, UIManagerType.FABRIC);
}

public void registerFabricEventListener(NodesManager nodesManager) {
if (fabricUIManager != null) {
fabricUIManager.getEventDispatcher().addListener(nodesManager);
}
public void registerFabricEventListener(NodesManager nodesManager) {
if (fabricUIManager != null) {
fabricUIManager.getEventDispatcher().addListener(nodesManager);
}
}

public void synchronouslyUpdateUIProps(int viewTag, ReadableMap uiProps) {
fabricUIManager.synchronouslyUpdateViewOnUIThread(viewTag, uiProps);
}
}
public void synchronouslyUpdateUIProps(int viewTag, ReadableMap uiProps) {
fabricUIManager.synchronouslyUpdateViewOnUIThread(viewTag, uiProps);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,139 +10,138 @@
import com.swmansion.reanimated.layoutReanimation.LayoutAnimations;
import com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder;
import com.swmansion.reanimated.nativeProxy.NativeProxyCommon;

import java.lang.ref.WeakReference;
import java.util.HashMap;

public class NativeProxy extends NativeProxyCommon {
@DoNotStrip
@SuppressWarnings("unused")
private final HybridData mHybridData;

public NativeProxy(ReactApplicationContext context, String valueUnpackerCode) {
super(context);
CallInvokerHolderImpl holder =
(CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder();
LayoutAnimations LayoutAnimations = new LayoutAnimations(context);
ReanimatedMessageQueueThread messageQueueThread = new ReanimatedMessageQueueThread();
mHybridData =
initHybrid(
context.getJavaScriptContextHolder().get(),
holder,
mAndroidUIScheduler,
LayoutAnimations,
messageQueueThread,
valueUnpackerCode);
prepareLayoutAnimations(LayoutAnimations);
installJSIBindings();
if (BuildConfig.DEBUG) {
checkCppVersion();
}
}

private native HybridData initHybrid(
long jsContext,
CallInvokerHolderImpl jsCallInvokerHolder,
AndroidUIScheduler androidUIScheduler,
LayoutAnimations LayoutAnimations,
MessageQueueThread messageQueueThread,
String valueUnpackerCode);

public native boolean isAnyHandlerWaitingForEvent(String eventName, int emitterReactTag);

public native void performOperations();

@Override
protected HybridData getHybridData() {
return mHybridData;
@DoNotStrip
@SuppressWarnings("unused")
private final HybridData mHybridData;

public NativeProxy(ReactApplicationContext context, String valueUnpackerCode) {
super(context);
CallInvokerHolderImpl holder =
(CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder();
LayoutAnimations LayoutAnimations = new LayoutAnimations(context);
ReanimatedMessageQueueThread messageQueueThread = new ReanimatedMessageQueueThread();
mHybridData =
initHybrid(
context.getJavaScriptContextHolder().get(),
holder,
mAndroidUIScheduler,
LayoutAnimations,
messageQueueThread,
valueUnpackerCode);
prepareLayoutAnimations(LayoutAnimations);
installJSIBindings();
if (BuildConfig.DEBUG) {
checkCppVersion();
}

public static NativeMethodsHolder createNativeMethodsHolder(LayoutAnimations layoutAnimations) {
WeakReference<LayoutAnimations> weakLayoutAnimations = new WeakReference<>(layoutAnimations);
return new NativeMethodsHolder() {
@Override
public void startAnimation(int tag, int type, HashMap<String, Object> values) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
HashMap<String, String> preparedValues = new HashMap<>();
for (String key : values.keySet()) {
String stringValue = values.get(key).toString();
if (key.endsWith("TransformMatrix")) {
preparedValues.put(key, simplifyStringNumbersList(stringValue));
} else {
preparedValues.put(key, stringValue);
}
}
layoutAnimations.startAnimationForTag(tag, type, preparedValues);
}
}

@Override
public boolean shouldAnimateExiting(int tag, boolean shouldAnimate) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
return layoutAnimations.shouldAnimateExiting(tag, shouldAnimate);
}
return false;
}

@Override
public boolean isLayoutAnimationEnabled() {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
return layoutAnimations.isLayoutAnimationEnabled();
}
return false;
}

@Override
public boolean hasAnimation(int tag, int type) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
return layoutAnimations.hasAnimationForTag(tag, type);
}
return false;
}

private native HybridData initHybrid(
long jsContext,
CallInvokerHolderImpl jsCallInvokerHolder,
AndroidUIScheduler androidUIScheduler,
LayoutAnimations LayoutAnimations,
MessageQueueThread messageQueueThread,
String valueUnpackerCode);

public native boolean isAnyHandlerWaitingForEvent(String eventName, int emitterReactTag);

public native void performOperations();

@Override
protected HybridData getHybridData() {
return mHybridData;
}

public static NativeMethodsHolder createNativeMethodsHolder(LayoutAnimations layoutAnimations) {
WeakReference<LayoutAnimations> weakLayoutAnimations = new WeakReference<>(layoutAnimations);
return new NativeMethodsHolder() {
@Override
public void startAnimation(int tag, int type, HashMap<String, Object> values) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
HashMap<String, String> preparedValues = new HashMap<>();
for (String key : values.keySet()) {
String stringValue = values.get(key).toString();
if (key.endsWith("TransformMatrix")) {
preparedValues.put(key, simplifyStringNumbersList(stringValue));
} else {
preparedValues.put(key, stringValue);
}
}
layoutAnimations.startAnimationForTag(tag, type, preparedValues);
}
}

@Override
public void clearAnimationConfig(int tag) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
layoutAnimations.clearAnimationConfigForTag(tag);
}
}
@Override
public boolean shouldAnimateExiting(int tag, boolean shouldAnimate) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
return layoutAnimations.shouldAnimateExiting(tag, shouldAnimate);
}
return false;
}

@Override
public boolean isLayoutAnimationEnabled() {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
return layoutAnimations.isLayoutAnimationEnabled();
}
return false;
}

@Override
public boolean hasAnimation(int tag, int type) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
return layoutAnimations.hasAnimationForTag(tag, type);
}
return false;
}

@Override
public void clearAnimationConfig(int tag) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
layoutAnimations.clearAnimationConfigForTag(tag);
}
}

@Override
public void cancelAnimation(int tag) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
layoutAnimations.cancelAnimationForTag(tag);
}
}
@Override
public void cancelAnimation(int tag) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
layoutAnimations.cancelAnimationForTag(tag);
}
}

@Override
public int findPrecedingViewTagForTransition(int tag) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
return layoutAnimations.findPrecedingViewTagForTransition(tag);
}
return -1;
}
@Override
public int findPrecedingViewTagForTransition(int tag) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
return layoutAnimations.findPrecedingViewTagForTransition(tag);
}
return -1;
}

public void checkDuplicateSharedTag(int viewTag, int screenTag) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
layoutAnimations.checkDuplicateSharedTag(viewTag, screenTag);
}
}
public void checkDuplicateSharedTag(int viewTag, int screenTag) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
layoutAnimations.checkDuplicateSharedTag(viewTag, screenTag);
}
}

public int[] getSharedGroup(int viewTag) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
return layoutAnimations.getSharedGroup(viewTag);
}
return new int[]{};
}
};
}
public int[] getSharedGroup(int viewTag) {
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
if (layoutAnimations != null) {
return layoutAnimations.getSharedGroup(viewTag);
}
return new int[] {};
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* This code was copied from android/build/generated/source/codegen/java/com/swmansion/reanimated/NativeReanimatedModuleSpec.java
* which was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
* This code was copied from
* android/build/generated/source/codegen/java/com/swmansion/reanimated/NativeReanimatedModuleSpec.java
* which was generated by
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
* <p>Do not edit this file as changes may cause incorrect behavior and will be lost once the code
* is regenerated.
*
* @generated by codegen project: GenerateModuleJavaSpec.js
*
* @nolint
*/

package com.swmansion.reanimated;

import com.facebook.proguard.annotations.DoNotStrip;
Expand All @@ -19,7 +19,8 @@
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import javax.annotation.Nonnull;

public abstract class NativeReanimatedModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
public abstract class NativeReanimatedModuleSpec extends ReactContextBaseJavaModule
implements TurboModule {
public static final String NAME = "ReanimatedModule";

public NativeReanimatedModuleSpec(ReactApplicationContext reactContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableMap;
import com.swmansion.reanimated.NodesManager;

class ReaCompatibility {
public ReaCompatibility(ReactApplicationContext reactApplicationContext) {
public ReaCompatibility(ReactApplicationContext reactApplicationContext) {}

}
public void registerFabricEventListener(NodesManager nodesManager) {
public void registerFabricEventListener(NodesManager nodesManager) {}

}
public void synchronouslyUpdateUIProps(int viewTag, ReadableMap uiProps) {

}
}
public void synchronouslyUpdateUIProps(int viewTag, ReadableMap uiProps) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ public class ReactFeatureFlagsWrapper {
public static void enableMountHooks() {
// no-op
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ public class ReactFeatureFlagsWrapper {
public static void enableMountHooks() {
ReactFeatureFlags.enableMountHooks = true;
}

}
Loading

0 comments on commit f60dadd

Please sign in to comment.