code:
/**
- NeuroSurfaceSkia — final "Apple-style" blob
*/
import React, { useEffect } from 'react';
import { View, StyleSheet } from 'react-native';
import {
Canvas, Path, Skia, Group, vec,
RadialGradient, BlurMask, Paint, Image,
} from '@shopify/react-native-skia';
import Animated, {
useSharedValue, withTiming, withRepeat,
useDerivedValue,
} from 'react-native-reanimated';
import { Spacing, getClarityGradient, getClarityColor } from '@/constants/Colors';
import { CognitionLevel } from '@/types';
// ---------- tiny 512×512 monochrome noise bitmap, cached once ----------
// const createNoiseBitmap = () => { ... };
// const noiseBmp = createNoiseBitmap();
// ---------- organic path ------------------------------------------------
const makeBlobPath = (R: number, t: number, clarity: CognitionLevel) => {
'worklet';
const pts = 48;
const ampl = Math.min(0.08, Math.max(0.05, 0.18 - clarity * 0.02));
const p: [number, number][] = [];
for (let i = 0; i < pts; ++i) {
const a = (i / pts) * Math.PI * 2;
const n = Math.sin(a * 3 + t * 2) * 0.6 + Math.sin(a * 7 + t) * 0.4;
const r = R * (1 + ampl * n);
p.push([Math.cos(a) * r, Math.sin(a) * r]);
}
const path = Skia.Path.Make();
for (let i = 0; i < pts; ++i) {
const p0 = p[(i - 1 + pts) % pts], p1 = p[i], p2 = p[(i + 1) % pts], p3 = p[(i + 2) % pts];
if (i === 0) path.moveTo(...p1);
path.cubicTo(
p1[0] + (p2[0] - p0[0]) / 6, p1[1] + (p2[1] - p0[1]) / 6,
p2[0] - (p3[0] - p1[0]) / 6, p2[1] - (p3[1] - p1[1]) / 6,
...p2
);
}
path.close();
return path;
};
// ---------- component ---------------------------------------------------
export default function NeuroSurfaceSkia({ clarity, size = 300 }: {
clarity: CognitionLevel | null;
size?: number;
}) {
const prog = useSharedValue(0);
const level = clarity ?? 3;
const speed = {1:8000,2:7000,3:6000,4:5000,5:4500}[level]!;
useEffect(() => { prog.value = withRepeat(withTiming(1,{duration:speed}), -1, false); }, [level, prog]);
const σ = 50, pad = σ3;
const canvas = size + pad2, R = size*0.35;
const baseScale = {1:0.85,2:0.9,3:0.95,4:1,5:1.05}[level]!;
const transform = useDerivedValue(()=>{
const s = baseScale + 0.04Math.sin(prog.valueMath.PI*2);
return [ { translateX:canvas/2 }, { translateY:canvas/2 }, { scale:s } ];
}, [prog, baseScale, canvas]);
const blobPath = useDerivedValue(()=>{
'worklet';
return makeBlobPath(R, prog.valueMath.PI2, level);
}, [prog, level, R]);
return (
<View style={{ width: size, height: size, alignItems:'center',justifyContent:'center' }}>
<Canvas style={{ width: canvas, height: canvas, margin: -pad, backgroundColor: 'white' }}>
{/* ── STEP A ── simple solid fill (CORRECTED as per user's Fix 1) ── */}
{/*
<Path
path={blobPath}
color="#00FF00" // Pass CSS-style hex string directly
style="fill" // Explicitly fill
/>
*/}
{/* ── STEP B ── core radial gradient only (Original user-provided structure) ── */}
{/*
<Path path={blobPath}>
<RadialGradient
c={vec(0,0)} r={R}
colors={[ // Strings directly as per user's previous correction
'#A8E6CF',
'#C6F6D5',
'#F7F7FF',
]}
positions={[0, 0.6, 1]}
/>
</Path>
*/}
{/* ── STEP C ── full pipeline (Testing without blendMode="screen") ── */}
<Group>
<Path path={blobPath}>
<RadialGradient
c={vec(0,0)} r={R}
colors={[
'rgba(198,246,213,0.8)',
'rgba(240,253,244,0)',
]}
/>
<BlurMask blur={σ} style="outer" />
</Path>
</Group>
<Path path={blobPath}>
<RadialGradient
c={vec(0,0)} r={R}
colors={[
'#A8E6CF',
'#C6F6D5',
'#F7F7FF',
]}
positions={[0,0.6,1]}
/>
</Path>
<Path path={blobPath}>
<Paint style="stroke" strokeWidth={1.2} color="rgba(255,255,255,0.18)" />
<BlurMask blur={6} style="solid" />
</Path>
</Group>
</Canvas>
</View>
);
}
/* ---------------- styles ---------------- */
// const styles = StyleSheet.create({ ... });
Okay, here's a summary of our debugging journey and the current status, framed as an update to an expert:
Subject: Debugging Skia Blob Rendering Issue - Isolation Progress
Hi Expert,
We've been systematically debugging an issue where a Skia-rendered blob component (NeuroSurfaceSkia) was appearing black instead of with its intended colors and effects. Here’s a summary of our progress using a minimal test version of the component:
1. Initial Problem: The blob was consistently rendering black, even when attempting to apply simple named colors or hex colors.
2. Key Breakthroughs & Successful Tests (using a step-by-step isolated rendering approach):
3. Current Issue - Full Pipeline Renders Black (STEP C):
-
When we activated the full rendering pipeline (STEP C), which includes the working core gradient plus a "bloom" effect layer and a "rim highlight" layer, the blob reverted to rendering black.
STEP C structure:
// Initially had blendMode="screen" here
<Group>
{/* Bloom Layer */}
<Path path={blobPath}>
<RadialGradient c={vec(0,0)} r={R} colors={['rgba(198,246,213,0.8)', 'rgba(240,253,244,0)']} />
<BlurMask blur={σ} style="outer" />
</Path>
</Group>
{/* Core Fill Layer (same as working STEP B) */}
<Path path={blobPath}>
<RadialGradient c={vec(0,0)} r={R} colors={['#A8E6CF', '#C6F6D5', '#F7F7FF']} positions={[0,0.6,1]} />
</Path>
{/* Rim Highlight Layer */}
<Path path={blobPath}>
<Paint style="stroke" strokeWidth={1.2} color="rgba(255,255,255,0.18)" />
<BlurMask blur={6} style="solid" />
</Path>
-
Troubleshooting STEP C:
- Our immediate prior test involved removing
blendMode="screen" from the Group containing the bloom layer.
- The user confirmed that after removing
blendMode="screen", STEP C still renders the blob as black.
4. Next Steps & Hypothesis:
Since the blob is still black even without blendMode="screen" in STEP C, the issue likely lies in:
- The drawing order or interaction of the layers: One of the new layers (bloom or rim highlight) might be opaquely drawing black over everything else.
- An issue within the bloom or rim highlight layers themselves: A problem with their specific gradients, paints, or blur masks causing them to render black and obscure underlying layers.
- The
backgroundColor: 'white' on the Canvas is confirmed.
We need to further isolate which part of STEP C is causing the problem. The next logical test would be to comment out the bloom and rim highlight layers individually to see if the core fill (which worked in STEP B) becomes visible again.
This summary should bring the expert up to speed. The key learning so far is the correct way to pass color strings directly to Skia JSX component props. The current mystery is why the combination of layers in STEP C results in black, even after removing the screen blend mode.