Skip to content

Commit 4217fd3

Browse files
authored
Adding custom spinner component (#614)
## Description Fixes re-renders of the loading spinner in the computer vision and LLM demo apps by using a custom spinner component that prevents flickering. ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [x] Bug fix (change which fixes an issue) - [ ] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [ ] Other (chores, tests, code style improvements etc.) ### Tested on - [ ] iOS - [x] Android ### Testing instructions Run demo app with uncached model. ### Screenshots <!-- Add screenshots here, if applicable --> ### Related issues Closes #589 ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings ### Additional notes <!-- Include any additional information, assumptions, or context that reviewers might need to understand this PR. -->
1 parent 82c41df commit 4217fd3

File tree

13 files changed

+99
-11
lines changed

13 files changed

+99
-11
lines changed

apps/computer-vision/app/classification/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Spinner from 'react-native-loading-spinner-overlay';
1+
import Spinner from '../../components/Spinner';
22
import { getImage } from '../../utils';
33
import { useClassification, EFFICIENTNET_V2_S } from 'react-native-executorch';
44
import { View, StyleSheet, Image, Text, ScrollView } from 'react-native';

apps/computer-vision/app/image_segmentation/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Spinner from 'react-native-loading-spinner-overlay';
1+
import Spinner from '../../components/Spinner';
22
import { BottomBar } from '../../components/BottomBar';
33
import { getImage } from '../../utils';
44
import {

apps/computer-vision/app/object_detection/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Spinner from 'react-native-loading-spinner-overlay';
1+
import Spinner from '../../components/Spinner';
22
import { BottomBar } from '../../components/BottomBar';
33
import { getImage } from '../../utils';
44
import {

apps/computer-vision/app/ocr/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Spinner from 'react-native-loading-spinner-overlay';
1+
import Spinner from '../../components/Spinner';
22
import { BottomBar } from '../../components/BottomBar';
33
import { getImage } from '../../utils';
44
import { useOCR, OCR_ENGLISH } from 'react-native-executorch';

apps/computer-vision/app/ocr_vertical/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Spinner from 'react-native-loading-spinner-overlay';
1+
import Spinner from '../../components/Spinner';
22
import { BottomBar } from '../../components/BottomBar';
33
import { getImage } from '../../utils';
44
import { useVerticalOCR, VERTICAL_OCR_ENGLISH } from 'react-native-executorch';

apps/computer-vision/app/style_transfer/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Spinner from 'react-native-loading-spinner-overlay';
1+
import Spinner from '../../components/Spinner';
22
import { BottomBar } from '../../components/BottomBar';
33
import { getImage } from '../../utils';
44
import {

apps/computer-vision/app/text_to_image/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
TouchableWithoutFeedback,
88
} from 'react-native';
99
import React, { useContext, useEffect, useState } from 'react';
10-
import Spinner from 'react-native-loading-spinner-overlay';
10+
import Spinner from '../../components/Spinner';
1111
import { useTextToImage, BK_SDM_TINY_VPRED_256 } from 'react-native-executorch';
1212
import { GeneratingContext } from '../../context';
1313
import ColorPalette from '../../colors';
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react';
2+
import { View, Text, StyleSheet, ActivityIndicator, Modal } from 'react-native';
3+
import ColorPalette from '../colors';
4+
5+
interface SpinnerProps {
6+
visible: boolean;
7+
textContent: string;
8+
}
9+
10+
const Spinner = ({ visible, textContent }: SpinnerProps) => {
11+
return (
12+
<Modal transparent={true} animationType="fade" visible={visible}>
13+
<View style={styles.overlay}>
14+
<View style={styles.container}>
15+
<ActivityIndicator size="large" color="#FFFFFF" />
16+
<Text style={styles.text}>{textContent}</Text>
17+
</View>
18+
</View>
19+
</Modal>
20+
);
21+
};
22+
23+
const styles = StyleSheet.create({
24+
overlay: {
25+
flex: 1,
26+
justifyContent: 'center',
27+
alignItems: 'center',
28+
backgroundColor: 'rgba(0, 0, 0, 0.1)',
29+
},
30+
container: {
31+
padding: 25,
32+
alignItems: 'center',
33+
justifyContent: 'center',
34+
},
35+
text: {
36+
marginTop: 15,
37+
color: ColorPalette.primary,
38+
fontSize: 18,
39+
fontWeight: 'bold',
40+
},
41+
});
42+
43+
export default Spinner;

apps/llm/app/llm/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {
1111
View,
1212
} from 'react-native';
1313
import SendIcon from '../../assets/icons/send_icon.svg';
14-
import Spinner from 'react-native-loading-spinner-overlay';
1514
import { useLLM, LLAMA3_2_1B_SPINQUANT } from 'react-native-executorch';
1615
import PauseIcon from '../../assets/icons/pause_icon.svg';
1716
import ColorPalette from '../../colors';
1817
import Messages from '../../components/Messages';
1918
import { useIsFocused } from '@react-navigation/native';
2019
import { GeneratingContext } from '../../context';
20+
import Spinner from '../../components/Spinner';
2121

2222
export default function LLMScreenWrapper() {
2323
const isFocused = useIsFocused();

apps/llm/app/llm_structured_output/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
View,
1212
} from 'react-native';
1313
import SendIcon from '../../assets/icons/send_icon.svg';
14-
import Spinner from 'react-native-loading-spinner-overlay';
14+
import Spinner from '../../components/Spinner';
1515
import {
1616
useLLM,
1717
fixAndValidateStructuredOutput,
@@ -224,6 +224,7 @@ const styles = StyleSheet.create({
224224
color: ColorPalette.primary,
225225
},
226226
bottomHelloText: {
227+
padding: 20,
227228
fontFamily: 'regular',
228229
fontSize: 20,
229230
lineHeight: 28,

0 commit comments

Comments
 (0)