Skip to content

fix: resolve gesture handler worklet conflicts and enhance color support#3

Merged
ashik112 merged 8 commits into
ashik112:mainfrom
mmestiyak:fix/gesture-handler-worklets-and-color-support
Aug 17, 2025
Merged

fix: resolve gesture handler worklet conflicts and enhance color support#3
ashik112 merged 8 commits into
ashik112:mainfrom
mmestiyak:fix/gesture-handler-worklets-and-color-support

Conversation

@mmestiyak

Copy link
Copy Markdown
Contributor

🎯 Problem

This PR addresses critical issues that prevented the library from working properly with React Native Reanimated and Gesture Handler:

  1. Worklet Conflicts: Mixed worklet/non-worklet callbacks caused react-native-gesture-handler errors
  2. Limited Color Support: Named colors ("red", "blue") and various hex formats didn't work with alpha transparency
  3. Expo SDK Compatibility: Peer dependency requirements were too strict for broader Expo SDK support

🔧 Solution

Worklet Resolution

  • Added .runOnJS(true) to Gesture.Pan() chain to force all callbacks to JavaScript thread
  • Removed all 'worklet' directives and runOnJS() wrappers from gesture handlers
  • Pre-computed color values outside worklet context to prevent synchronous UI thread calls

Enhanced Color Support

  • Integrated color-alpha library for robust color handling
  • Added support for named colors ("red", "blue", "green", etc.)
  • Enhanced hex code support (3-digit, 6-digit, with/without #)
  • Proper alpha transparency handling for all color formats

📦 Dependencies

  • Added: color-alpha for robust color manipulation
  • Updated: Peer dependency requirements for broader compatibility

🔄 Breaking Changes

📝 Example Usage

<Joystick
  size={150}
  color="red"  // ✨ Named colors now work!
  onMove={(data) => {
    // ✨ No more worklet errors!
    console.log('Position:', data.position);
    updateState(data.position);
  }}
/>

Fixes: Worklet conflicts, color handling limitations, and compatibility issues
Enhances: Developer experience with more intuitive color API and error-free gesture handling

- Add runOnJS(true) modifier to Pan gesture to fix mixed worklet/JS callback warnings
- Remove worklet directives from gesture callbacks for consistent JS thread execution
- Add color-alpha dependency for robust color manipulation
- Support named colors, hex, rgb, and rgba formats with proper alpha transparency
- Clean up unused runOnJS imports and improve code maintainability

Fixes gesture handler error: 'Some of the callbacks in the gesture are worklets and some are not'
Enhances color prop to accept any valid CSS color format with alpha support
@ashik112 ashik112 merged commit c2873f2 into ashik112:main Aug 17, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants