Skip to content

Commit cee46c4

Browse files
committed
feat(api-updates): improved interfaces of both cupertino and material component
1 parent feb99e8 commit cee46c4

File tree

4 files changed

+92
-50
lines changed

4 files changed

+92
-50
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"react-native": "../src/cupertino-activity-indicator/index",
3+
"main": "../lib/commonjs/cupertino-activity-indicator/index",
4+
"module": "../lib/module/cupertino-activity-indicator/index",
5+
"types": "../lib/typescript/src/cupertino-activity-indicator/index.d.ts"
6+
}

example/src/App.tsx

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import * as React from 'react';
22

33
import { StyleSheet, Text, View } from 'react-native';
4-
import {
5-
DeterminateMaterialCircularProgressIndicator,
6-
IndeterminateMaterialCircularProgressIndicator,
7-
} from 'react-native-skia-ui/material-circular-progress-indicator';
4+
import { MaterialCircularProgressIndicator } from 'react-native-skia-ui/material-circular-progress-indicator';
85
import { useSharedValue, withTiming } from 'react-native-reanimated';
96
import { CupertinoActivityIndicator } from 'react-native-skia-ui/cupertino-activity-indicator';
107
export default function App() {
@@ -18,33 +15,33 @@ export default function App() {
1815
});
1916
return (
2017
<View style={styles.container}>
21-
<Text>DeterminateMaterialCircularProgressIndicator</Text>
22-
<DeterminateMaterialCircularProgressIndicator
18+
<Text>Determinate progress indicators</Text>
19+
<MaterialCircularProgressIndicator.Determinate
2320
size={56}
2421
valueColor="green"
2522
strokeWidth={5}
2623
strokeCap="round"
2724
value={progress}
2825
/>
29-
<DeterminateMaterialCircularProgressIndicator
26+
<MaterialCircularProgressIndicator.Determinate
3027
size={100}
3128
valueColor="blue"
3229
strokeWidth={4}
3330
strokeCap="round"
3431
value={progress}
3532
/>
36-
<CupertinoActivityIndicator
33+
<CupertinoActivityIndicator.PartiallyRevealed
3734
color="black"
3835
progress={progress}
3936
radius={50}
4037
/>
41-
<Text>IndeterminateMaterialCircularProgressIndicator</Text>
42-
<IndeterminateMaterialCircularProgressIndicator
38+
39+
<Text>Indeterminate progress indicators</Text>
40+
<MaterialCircularProgressIndicator.Indeterminate
4341
size={40}
4442
valueColor="black"
4543
/>
46-
47-
<IndeterminateMaterialCircularProgressIndicator
44+
<MaterialCircularProgressIndicator.Indeterminate
4845
size={100}
4946
valueColor="red"
5047
backgroundColor={'#f0f0f0'}

src/cupertino-activity-indicator/index.tsx

+42-19
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type InternalProps = {
108108
};
109109

110110
export type CupertinoActivityIndicatorProps = {
111-
color: string;
111+
color: PlainValueOrAnimatedValue<string>;
112112
/**
113113
* Whether to show the indicator (true, the default) or hide it (false).
114114
* @default true
@@ -120,17 +120,21 @@ export type CupertinoActivityIndicatorProps = {
120120
* Defaults to 10 pixels.
121121
*/
122122
radius?: PlainValueOrAnimatedValue<number>;
123-
/**
124-
* Determines the percentage of spinner ticks that will be shown. Typical usage would
125-
* display all ticks, however, this allows for more fine-grained control such as
126-
* during pull-to-refresh when the drag-down action shows one tick at a time as
127-
* the user continues to drag down.
128-
*
129-
* Defaults to one. Must be between zero and one, inclusive.
130-
*/
131-
progress?: PlainValueOrAnimatedValue<number>;
132123
};
133124

125+
export type CupertinoActivityIndicatorPartiallyRevealedProps =
126+
CupertinoActivityIndicatorProps & {
127+
/**
128+
* Determines the percentage of spinner ticks that will be shown. Typical usage would
129+
* display all ticks, however, this allows for more fine-grained control such as
130+
* during pull-to-refresh when the drag-down action shows one tick at a time as
131+
* the user continues to drag down.
132+
*
133+
* Must be between zero and one, inclusive.
134+
*/
135+
progress: PlainValueOrAnimatedValue<number>;
136+
};
137+
134138
const _Content = (props: InternalProps) => {
135139
const animationValue = useDuration({
136140
stopped: useSharedValue(false),
@@ -167,16 +171,35 @@ const _Content = (props: InternalProps) => {
167171
);
168172
};
169173

170-
export const CupertinoActivityIndicator = (
174+
const CupertinoActivityIndicator_ = (
171175
props: CupertinoActivityIndicatorProps
176+
) => {
177+
const { color, animating, radius } = props;
178+
179+
return _Content({
180+
color: useToSharedValue(color),
181+
animating: useToSharedValueOptional(animating, true),
182+
radius: useToSharedValueOptional(radius, _kDefaultIndicatorRadius),
183+
progress: useToSharedValue(1),
184+
});
185+
};
186+
187+
const CupertinoActivityIndicatorPartial = (
188+
props: CupertinoActivityIndicatorPartiallyRevealedProps
172189
) => {
173190
const { color, animating, radius, progress } = props;
174-
return (
175-
<_Content
176-
color={useToSharedValue(color)}
177-
animating={useToSharedValueOptional(animating, true)}
178-
radius={useToSharedValueOptional(radius, _kDefaultIndicatorRadius)}
179-
progress={useToSharedValueOptional(progress, 1)}
180-
/>
181-
);
191+
192+
return _Content({
193+
color: useToSharedValue(color),
194+
animating: useToSharedValueOptional(animating, true),
195+
radius: useToSharedValueOptional(radius, _kDefaultIndicatorRadius),
196+
progress: useToSharedValue(progress),
197+
});
182198
};
199+
200+
export const CupertinoActivityIndicator = Object.assign(
201+
CupertinoActivityIndicator_,
202+
{
203+
PartiallyRevealed: CupertinoActivityIndicatorPartial,
204+
}
205+
);

src/material-circular-progress-indicator/MaterialCircularProgressIndicator.tsx

+35-19
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ type InternalProps = {
124124
strokeAlign?: number;
125125
};
126126

127-
const Content_ = ({
127+
const _Content = ({
128128
size: _size,
129129
strokeWidth,
130130
value,
@@ -209,11 +209,6 @@ export type MaterialCircularProgressIndicatorProps = SetOptional<
209209
InternalOrSharedProps,
210210
DefaultedKeys | 'stopped' | 'value'
211211
>;
212-
/*
213-
type SetRequiredAndNonNullable<T, K extends keyof T> = SetRequired<
214-
SetNonNullable<T, K>,
215-
K
216-
>; */
217212

218213
export type DeterminateMaterialCircularProgressIndicatorProps = SetOptional<
219214
SetNonNullable<Omit<InternalOrSharedProps, 'stopped'>, 'value'>,
@@ -225,17 +220,10 @@ export type IndeterminateMaterialCircularProgressIndicatorProps = SetOptional<
225220
DefaultedKeys | 'stopped'
226221
>;
227222

228-
/**
229-
*
230-
* @description Component has two modes: determinate and indeterminate. Which are controlled by the `value` prop.
231-
* If `value` is undefined, the progress indicator will be indeterminate.
232-
* If `value` is a number between 0 and 1, the progress indicator will be determinate.
233-
* Not all props applies to both modes. For more type safety, use `DeterminateMaterialCircularProgressIndicator` and `IndeterminateMaterialCircularProgressIndicator` instead.
234-
*/
235-
export const MaterialCircularProgressIndicator = (
223+
const MaterialCircularProgressIndicator_ = (
236224
props: MaterialCircularProgressIndicatorProps
237225
) => (
238-
<Content_
226+
<_Content
239227
{...props}
240228
size={useToSharedValue(props.size)}
241229
value={useToSharedValue(props.value)}
@@ -246,10 +234,10 @@ export const MaterialCircularProgressIndicator = (
246234
/>
247235
);
248236

249-
export const IndeterminateMaterialCircularProgressIndicator = (
237+
const IndeterminateMaterialCircularProgressIndicator = (
250238
props: IndeterminateMaterialCircularProgressIndicatorProps
251239
) => (
252-
<Content_
240+
<_Content
253241
{...props}
254242
size={useToSharedValue(props.size)}
255243
value={useSharedValue(undefined)}
@@ -260,10 +248,10 @@ export const IndeterminateMaterialCircularProgressIndicator = (
260248
/>
261249
);
262250

263-
export const DeterminateMaterialCircularProgressIndicator = (
251+
const DeterminateMaterialCircularProgressIndicator = (
264252
props: DeterminateMaterialCircularProgressIndicatorProps
265253
) => (
266-
<Content_
254+
<_Content
267255
{...props}
268256
size={useToSharedValue(props.size)}
269257
value={useToSharedValue(props.value)}
@@ -273,3 +261,31 @@ export const DeterminateMaterialCircularProgressIndicator = (
273261
valueColor={useToSharedValue(props.valueColor)}
274262
/>
275263
);
264+
265+
/**
266+
*
267+
* @description Component has two modes: determinate and indeterminate. Which are controlled by the `value` prop.
268+
* If `value` is undefined, the progress indicator will be indeterminate.
269+
* If `value` is a number between 0 and 1, the progress indicator will be determinate.
270+
*
271+
*
272+
* Not all props applies to both modes. For more type safety, use `MaterialCircularProgressIndicator.Determinate` and `MaterialCircularProgressIndicator.Indeterminate` components.
273+
*/
274+
export const MaterialCircularProgressIndicator = Object.assign(
275+
MaterialCircularProgressIndicator_,
276+
{
277+
Indeterminate: IndeterminateMaterialCircularProgressIndicator,
278+
Determinate: DeterminateMaterialCircularProgressIndicator,
279+
}
280+
);
281+
282+
export {
283+
/**
284+
* @deprecated use `MaterialCircularProgressIndicator.Indeterminate` instead
285+
*/
286+
IndeterminateMaterialCircularProgressIndicator,
287+
/**
288+
* @deprecated use `MaterialCircularProgressIndicator.Determinate` instead
289+
*/
290+
DeterminateMaterialCircularProgressIndicator,
291+
};

0 commit comments

Comments
 (0)