Replies: 4 comments 1 reply
-
@galgord where you able to implement this ?? |
Beta Was this translation helpful? Give feedback.
-
Here is what I came up with, it uses two sweep gradients similar to the example you gave. See the code running on this Snack: https://snack.expo.dev/@dharrisbaird/glowing-border import React, { useEffect } from "react";
import { Dimensions } from "react-native";
import {
Blur,
Canvas,
Group,
RoundedRect,
SweepGradient,
vec,
} from "@shopify/react-native-skia";
import {
Easing,
useDerivedValue,
useSharedValue,
withRepeat,
withTiming,
} from "react-native-reanimated";
const { width: screenWidth, height: screenHeight } = Dimensions.get("window");
const GLOW_COLOR = "#1976edFF";
const GLOW_BG_COLOR = "#1976ed00"; // Should be the same color as GLOW_COLOR but fully transparent
const BACKGROUND_COLOR = "#1D1E22";
const BOX_COLOR = "#292a2e";
const GlowingBorder = ({
width = 200,
height = 200,
glowSize = 0.2,
blurRadius = 20,
}) => {
const rotation = useSharedValue(0);
const centerX = width / 2;
const centerY = height / 2;
const centerVec = vec(centerX, centerY);
useEffect(() => {
rotation.value = withRepeat(
withTiming(2, {
duration: 4000,
easing: Easing.linear,
}),
-1,
false,
);
}, []);
const animatedRotation = useDerivedValue(() => {
return [{ rotate: Math.PI * rotation.value }];
}, [rotation]);
const GlowGradient = () => {
return (
<RoundedRect r={10} x={0} y={0} width={width} height={height}>
<SweepGradient
origin={centerVec}
c={centerVec}
colors={[GLOW_BG_COLOR, GLOW_COLOR, GLOW_COLOR, GLOW_BG_COLOR]}
start={0}
end={360 * glowSize}
transform={animatedRotation}
/>
</RoundedRect>
);
};
return (
<Canvas style={{ flex: 1, backgroundColor: BACKGROUND_COLOR }}>
<Group
origin={{ x: screenWidth / 2, y: screenHeight / 2 }}
transform={[{translate: [(screenWidth - width) / 2, (screenHeight - height) / 2]}]}
>
{/* Blurred Glow */}
<Group>
<GlowGradient />
<Blur blur={blurRadius} />
</Group>
{/* Outline */}
<GlowGradient />
{/* Box overlay */}
<RoundedRect
r={10}
x={5}
y={5}
width={width - 10}
height={height - 10}
color={BOX_COLOR}
/>
</Group>
</Canvas>
);
};
export default GlowingBorder; |
Beta Was this translation helpful? Give feedback.
-
This is really cool @harrisbaird :) |
Beta Was this translation helpful? Give feedback.
-
@harrisbaird Looks great! Do you have an updated version of this? The snack is not working and I can't get this to work with locally either, getting a single animation frame frozen in time. Seems like the component is not getting re-rendered despite |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all,
I am trying to recreate this and this https://codepen.io/liyrofx/pen/poVZeEG but is the furthers I have gotten. Can anyone help please?
Beta Was this translation helpful? Give feedback.
All reactions