Hello! I'm developing a plugin to switch between color modes (light/dark) for multiple collections at once, and I'm facing some challenges. I have several collections that control different aspects of the light/dark mode theming, and I need to apply or switch all of them simultaneously on selected frames (or the whole page if possible). Here's what I've tried so far:
First Approach - setVariableModesAsync
- Tried using the setVariableModesAsync method to apply modes
- The code correctly identified collections and their modes
- Issue: Changes weren't applied visually, although logs indicated success
Second Approach - setBoundVariableForPaint
- Switched to using setBoundVariableForPaint for specific colors
- Tried processing each variable individually
- Issue: Received errors related to paint type and properties not found
Third Approach - setVariableModeForCollectionAsync
Based on the latest documentation (Update 83), changed to use setVariableModeForCollectionAsync. Implemented logic to:
- Identify only COLOR type variables
- Collect all color collections linked to the element
- Apply the selected mode to each collection
- Issue: Code executes without errors, but visual changes don't happen
Current code:
- First identifies all collections containing color variables
- Filters only 'COLOR' type variables using variable.resolvedType === 'COLOR'
- Uses setVariableModeForCollectionAsync to apply the mode to the entire collection
- When a mode is already applied, it should switch to the opposite mode
Relevant logs:
- Plugin correctly identifies available collections
- Finds light/dark modes in each collection
- Confirms mode application (selectedModeId: "3683:1")
- No errors in console
Could someone help me understand:
- Why aren't the changes being applied visually when switching between modes?
- What's the correct way to apply color modes via Figma API across multiple collections?
- Are there any limitations or specific requirements for switching modes that I might be missing?
Any help or guidance would be greatly appreciated!