Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ class ReanimatedProxy {
fun <T : Event<T>> sendEvent(event: T, reactApplicationContext: ReactContext) {
// no-op
}

companion object {
const val REANIMATED_INSTALLED = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,4 @@ class ReanimatedProxy {

reanimatedModule?.nodesManager?.onEventDispatch(event)
}

companion object {
const val REANIMATED_INSTALLED = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.facebook.react.turbomodule.core.interfaces.BindingsInstallerHolder
import com.facebook.react.turbomodule.core.interfaces.TurboModuleWithJSIBindings
import com.facebook.soloader.SoLoader
import com.swmansion.gesturehandler.NativeRNGestureHandlerModuleSpec
import com.swmansion.gesturehandler.ReanimatedProxy
import com.swmansion.gesturehandler.core.GestureHandler
import com.swmansion.gesturehandler.react.events.RNGestureHandlerEventDispatcher

Expand All @@ -29,6 +28,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
@DoNotStrip
@Suppress("unused")
private var mHybridData: HybridData = initHybrid()
private var isReanimatedAvailable = false
private var uiRuntimeDecorated = false
private val registry: RNGestureHandlerRegistry
get() = registries[moduleId]!!
Expand Down Expand Up @@ -62,7 +62,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :

@ReactMethod
override fun createGestureHandler(handlerName: String, handlerTagDouble: Double, config: ReadableMap): Boolean {
if (ReanimatedProxy.REANIMATED_INSTALLED && !uiRuntimeDecorated) {
if (isReanimatedAvailable && !uiRuntimeDecorated) {
uiRuntimeDecorated = decorateUIRuntime()
}

Expand Down Expand Up @@ -124,6 +124,11 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
@ReactMethod
override fun flushOperations() = Unit

@ReactMethod
override fun setReanimatedAvailability() {
Comment thread
j-piasecki marked this conversation as resolved.
Outdated
isReanimatedAvailable = true
}

@DoNotStrip
@Suppress("unused")
fun setGestureHandlerState(handlerTag: Int, newState: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ @implementation RNGestureHandlerModule {
jsi::Runtime *_rnRuntime;
int _moduleId;

bool _checkedIfReanimatedIsAvailable;
bool _isReanimatedAvailable;
bool _uiRuntimeDecorated;
}
Expand Down Expand Up @@ -121,10 +120,6 @@ - (bool)installUIRuntimeBindings

- (NSNumber *)createGestureHandler:(NSString *)handlerName handlerTag:(double)handlerTag config:(NSDictionary *)config
{
if (!_checkedIfReanimatedIsAvailable) {
_isReanimatedAvailable = [self.moduleRegistry moduleForName:"ReanimatedModule"] != nil;
}

if (_isReanimatedAvailable && !_uiRuntimeDecorated) {
_uiRuntimeDecorated = [self installUIRuntimeBindings];
}
Expand Down Expand Up @@ -191,6 +186,11 @@ - (void)flushOperations
}];
}

- (void)setReanimatedAvailability
Comment thread
j-piasecki marked this conversation as resolved.
Outdated
{
_isReanimatedAvailable = YES;
}

- (void)setGestureState:(int)state forHandler:(int)handlerTag
{
if (RCTIsMainQueue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GestureUpdateEventWithHandlerData,
SharedValue,
} from '../../v3/types';
import { NativeProxy } from '../../v3/NativeProxy';

export type ReanimatedContext<THandlerData> = {
lastUpdateEvent: GestureUpdateEventWithHandlerData<THandlerData> | undefined;
Expand Down Expand Up @@ -80,6 +81,7 @@ let Reanimated:

try {
Reanimated = require('react-native-reanimated');
NativeProxy.setReanimatedAvailability();
} catch (e) {
// When 'react-native-reanimated' is not available we want to quietly continue
// @ts-ignore TS demands the variable to be initialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Spec extends TurboModule {
configureRelations: (handlerTag: Double, relations: Object) => void;
dropGestureHandler: (handlerTag: Double) => void;
flushOperations: () => void;
setReanimatedAvailability: () => void;
Comment thread
j-piasecki marked this conversation as resolved.
Outdated
}

export default TurboModuleRegistry.getEnforcing<Spec>('RNGestureHandlerModule');
3 changes: 3 additions & 0 deletions packages/react-native-gesture-handler/src/v3/NativeProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ export const NativeProxy = {
RNGestureHandlerModule.configureRelations(handlerTag, relations);
});
},
setReanimatedAvailability: () => {
RNGestureHandlerModule.setReanimatedAvailability();
},
} as const;
Loading