1- import React , { useEffect , useRef , useState } from 'react' ;
1+ import { useEffect , useRef , useState } from 'react' ;
2+ import Icon from 'react-native-vector-icons/FontAwesome5' ;
23import AsyncStorage from '@react-native-async-storage/async-storage' ;
34import DraggableFlatList , { OpacityDecorator } from 'react-native-draggable-flatlist' ;
45import UnitValue from '../components/UnitValue' ;
56import ListUnitItem from '../components/ListUnitItem' ;
67import Snackbar from 'react-native-snackbar' ;
7- import { RefreshControl } from 'react-native-gesture-handler' ;
88import { StyleSheet , TouchableOpacity , View } from 'react-native' ;
99import { Text , useTheme } from '@rneui/themed' ;
1010import { convertCurrency , getEuropeanCentralBankRates } from '../utils/currencies' ;
1111import { useTranslation } from 'react-i18next' ;
1212import { fractionToNumber } from '../utils/conversion' ;
13+ import { Button } from '@rneui/base' ;
14+ import { ActivityIndicator } from 'react-native' ;
1315
1416
1517const ConvertCurrencyScreen = ( { navigation } ) => {
@@ -19,7 +21,6 @@ const ConvertCurrencyScreen = ({ navigation }) => {
1921 const { t } = useTranslation ( ) ;
2022 const isInitialized = useRef ( false ) ;
2123 const [ isRefreshing , setIsRefreshing ] = useState ( false ) ;
22- const [ isDragging , setIsDragging ] = useState ( false ) ;
2324 const [ refUnit , setRefUnit ] = useState ( defaultUnit ) ;
2425 const [ value , setValue ] = useState ( 0 ) ;
2526 const [ fxRate , setFxRate ] = useState ( { } ) ;
@@ -35,10 +36,9 @@ const ConvertCurrencyScreen = ({ navigation }) => {
3536
3637 setFxRate ( newFxRate ) ;
3738 saveCurrencyOrder ( data ) ;
38- setIsDragging ( false ) ;
3939 }
4040
41- const keyExtractor = ( item , index ) => item + index ;
41+ const keyExtractor = ( item , _index ) => item . iso ;
4242
4343 const renderItem = ( { item, drag } ) => {
4444 const isReferenceUnit = item . iso == refUnit . iso ;
@@ -205,20 +205,19 @@ const ConvertCurrencyScreen = ({ navigation }) => {
205205 setValue = { setValue }
206206 unit = { refUnit }
207207 />
208- < Text > { t ( 'update' ) } : { fxRate . day } ({ t ( 'sourceECB' ) } )</ Text >
208+ < View style = { { display : 'flex' , flexDirection : 'row' , alignItems : 'center' } } >
209+ < Text > { t ( 'update' ) } : { fxRate . day } ({ t ( 'sourceECB' ) } )</ Text >
210+ < Button size = 'sm' type = 'clear' color = { theme . colors . white } onPress = { fetchFxRate } disabled = { isRefreshing } >
211+ < Icon name = "sync" solid = { false } size = { 24 } color = { theme . colors . primary } />
212+ </ Button >
213+ </ View >
214+ { isRefreshing && < ActivityIndicator size = "large" /> }
209215 < View style = { { flex : 1 , width : '100%' } } >
210216 < DraggableFlatList
211217 data = { fxRate . rates ?? [ ] }
212- refreshControl = {
213- < RefreshControl
214- enabled = { ! isDragging }
215- onRefresh = { fetchFxRate }
216- refreshing = { isRefreshing }
217- />
218- }
218+ refreshing = { isRefreshing }
219219 renderItem = { renderItem }
220220 keyExtractor = { keyExtractor }
221- onDragBegin = { ( ) => setIsDragging ( true ) }
222221 onDragEnd = { onDragEnd }
223222 />
224223 </ View >
0 commit comments