Skip to content

Commit c96e6a0

Browse files
committed
fix: improve WidgetPreview
1 parent 4d32b2a commit c96e6a0

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

src/api/WidgetPreview.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ export function WidgetPreview({
5757
const isAndroid = Platform.OS === 'android';
5858
const [preview, setPreview] = useState<WidgetPreviewData | null>();
5959
const [error, setError] = useState(null);
60+
const [loading, setLoading] = useState(true);
6061

6162
useEffect(() => {
6263
async function init() {
6364
try {
65+
setLoading(true);
6466
const data = await AndroidWidget.createPreview(
6567
buildWidgetTree(renderWidget({ width, height })),
6668
width,
@@ -69,15 +71,16 @@ export function WidgetPreview({
6971

7072
setPreview(data);
7173
setError(null);
74+
setLoading(false);
7275
} catch (e: any) {
7376
console.error(e);
7477
setError(e?.message ?? 'Error rendering widget');
78+
setLoading(false);
7579
}
7680
}
7781
if (isAndroid) {
7882
init();
7983
}
80-
return () => setPreview(null);
8184
}, [isAndroid, renderWidget, width, height]);
8285

8386
function onPress(props: OnClick): void {
@@ -123,8 +126,23 @@ export function WidgetPreview({
123126
onClick={onPress}
124127
highlightClickableAreas={highlightClickableAreas}
125128
/>
126-
) : (
127-
<ActivityIndicator size="large" />
129+
) : null}
130+
131+
{loading && (
132+
<View
133+
style={{
134+
position: 'absolute',
135+
left: 0,
136+
right: 0,
137+
top: 0,
138+
bottom: 0,
139+
alignItems: 'center',
140+
justifyContent: 'center',
141+
backgroundColor: '#00000040',
142+
}}
143+
>
144+
<ActivityIndicator size="large" />
145+
</View>
128146
)}
129147
</PreviewContainer>
130148
);
@@ -267,8 +285,6 @@ function ClickableAreaButton({
267285
height: area.height,
268286
}}
269287
>
270-
{/* Clip the ripple to the corners: borderRadius + overflow must WRAP the touchable (not sit on
271-
its child), with an explicit bounded Ripple — the default background won't clip (RN #25342). */}
272288
<View
273289
style={{
274290
width: '100%',
@@ -277,15 +293,13 @@ function ClickableAreaButton({
277293
overflow: 'hidden',
278294
}}
279295
>
280-
<TouchableNativeFeedback
281-
onPress={() => onClick(area)}
282-
background={TouchableNativeFeedback.Ripple('rgba(150, 150, 150, 0.35)', false)}
283-
>
296+
<TouchableNativeFeedback onPress={() => onClick(area)} useForeground>
284297
<View
285298
style={{
286299
width: '100%',
287300
height: '100%',
288301
borderColor: 'red',
302+
borderRadius: area.borderRadius,
289303
borderWidth: highlightClickableAreas ? 1 : 0,
290304
}}
291305
/>
@@ -298,12 +312,12 @@ function ClickableAreaButton({
298312

299313
function ClickableAreaBorder() {
300314
return (
301-
<View pointerEvents="none" style={StyleSheet.absoluteFill}>
315+
<>
302316
<View style={styles.clickableHighlightTopLeft} />
303317
<View style={styles.clickableHighlightTopRight} />
304318
<View style={styles.clickableHighlightBottomLeft} />
305319
<View style={styles.clickableHighlightBottomRight} />
306-
</View>
320+
</>
307321
);
308322
}
309323

0 commit comments

Comments
 (0)