-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5814516
commit 71437a2
Showing
9 changed files
with
138 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import { Defs, LinearGradient, Stop } from 'react-native-svg'; | ||
import { CircleGradientProps } from './types'; | ||
|
||
const CircleGradient: React.FC<CircleGradientProps> = ({ | ||
activeStrokeSecondaryColor, | ||
activeStrokeColor, | ||
}) => { | ||
if (activeStrokeSecondaryColor) | ||
return ( | ||
<Defs> | ||
<LinearGradient id="grad" x1="0%" y1="0%" x2="0%" y2="100%"> | ||
<Stop offset="0%" stopColor={activeStrokeSecondaryColor} /> | ||
<Stop offset="100%" stopColor={activeStrokeColor} /> | ||
</LinearGradient> | ||
</Defs> | ||
); | ||
return null; | ||
}; | ||
|
||
export default React.memo(CircleGradient); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
|
||
export interface CircleGradientProps { | ||
/** | ||
* active progress circle color | ||
*/ | ||
activeStrokeColor?: string; | ||
/** | ||
* active progress secondary color. Use this to provide a gradient effect | ||
*/ | ||
activeStrokeSecondaryColor?: string | null; | ||
} | ||
declare const CircleGradient: React.FC<CircleGradientProps>; | ||
export default CircleGradient; | ||
// # sourceMappingURL=index.d.ts.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useCallback, useMemo } from 'react'; | ||
|
||
export interface UseCircleValuesProps { | ||
radius?: number; | ||
activeStrokeWidth?: number; | ||
inActiveStrokeWidth?: number; | ||
} | ||
|
||
export default function useCircleValues({ | ||
radius = 60, | ||
activeStrokeWidth = 10, | ||
inActiveStrokeWidth = 10, | ||
}: UseCircleValuesProps) { | ||
const isSameStrokeWidth = useMemo( | ||
() => activeStrokeWidth === inActiveStrokeWidth, | ||
[activeStrokeWidth, inActiveStrokeWidth] | ||
); | ||
|
||
const isActiveStrokeBigger = useMemo(() => { | ||
return activeStrokeWidth > inActiveStrokeWidth; | ||
}, [activeStrokeWidth, inActiveStrokeWidth]); | ||
|
||
const findRadius = useCallback(() => { | ||
if (isSameStrokeWidth) { | ||
return radius + inActiveStrokeWidth / 2; | ||
} | ||
if (isActiveStrokeBigger) { | ||
return radius + activeStrokeWidth / 2; | ||
} | ||
return radius + inActiveStrokeWidth / 2; | ||
}, [ | ||
isSameStrokeWidth, | ||
isActiveStrokeBigger, | ||
radius, | ||
inActiveStrokeWidth, | ||
activeStrokeWidth, | ||
]); | ||
|
||
const inactiveCircleRadius = useMemo(() => findRadius(), [findRadius]); | ||
|
||
const activeCircleRadius = useMemo(() => findRadius(), [findRadius]); | ||
|
||
const circleCircumference = useMemo(() => 2 * Math.PI * activeCircleRadius, [ | ||
activeCircleRadius, | ||
]); | ||
|
||
return { | ||
inactiveCircleRadius, | ||
activeCircleRadius, | ||
circleCircumference, | ||
}; | ||
} |