Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should raise an error when call with invalid argument', () => {
// $ExpectError: first argument must be number or array if numbers
Asset.loadAsync('');
Asset.loadAsync([
1,
// $ExpectError: must be number
'',
]);
});
});
it('should raise an error when call with invalid argument', () => {
// $ExpectError: first argument must be number or array if numbers
Asset.loadAsync('');
Asset.loadAsync([
1,
// $ExpectError: must be number
'',
]);
});
});
it('should raise an error when call with invalid argument', () => {
// $ExpectError: first argument must be a string
Asset.fromURI(1);
});
});
it('should raise an error when call with invalid argument', () => {
// $ExpectError: first argument must be an object
Asset.fromMetadata(true);
// $ExpectError: missing required props
Asset.fromMetadata({});
});
});
it('should raise an error when call with invalid argument', () => {
// $ExpectError: first argument must be an object
Asset.fromMetadata(true);
// $ExpectError: missing required props
Asset.fromMetadata({});
});
});
function _getAssetForSource(source: FontSource): Asset {
if (source instanceof Asset) {
return source;
}
if (!isWeb && typeof source === 'string') {
return Asset.fromURI(source);
}
if (isWeb || typeof source === 'number') {
return Asset.fromModule(source);
}
// @ts-ignore Error: Type 'string' is not assignable to type 'Asset'
// We can't have a string here, we would have thrown an error if !isWeb
// or returned Asset.fromModule if isWeb.
return source;
}
export function getAssetForSource(source: FontSource): Asset | FontResource {
if (source instanceof Asset) {
return source;
}
if (typeof source === 'string') {
return Asset.fromURI(source);
} else if (typeof source === 'number') {
return Asset.fromModule(source);
} else if (typeof source === 'object' && typeof source.uri !== 'undefined') {
return getAssetForSource(source.uri);
}
// @ts-ignore Error: Type 'string' is not assignable to type 'Asset'
// We can't have a string here, we would have thrown an error if !isWeb
// or returned Asset.fromModule if isWeb.
return source;
}
async _loadAssetsAsync() {
try {
const iconRequires = Object.keys(Icons).map(key => Icons[key]);
const assetPromises: Promise[] = [
Asset.loadAsync(iconRequires),
Asset.loadAsync(StackAssets),
// @ts-ignore
Font.loadAsync(Ionicons.font),
// @ts-ignore
Font.loadAsync(Entypo.font),
// @ts-ignore
Font.loadAsync(MaterialIcons.font),
Font.loadAsync({
'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
}),
];
if (Platform.OS !== 'web')
assetPromises.push(
Font.loadAsync({
Roboto: 'https://github.com/google/fonts/raw/master/apache/roboto/Roboto-Regular.ttf',
})
);
routeName: 'HeaderBackgroundFade',
},
{
component: DragLimitedToModal,
title: 'Drag limited to modal',
routeName: 'DragLimitedToModal',
},
{
component: StackAnimationConsumerStack,
title: 'Stack animation consumer stack',
routeName: 'StackAnimationConsumerStack',
},
];
// Cache images
Asset.loadAsync(StackAssets);
class Home extends React.Component {
static navigationOptions = {
title: 'Examples',
};
_renderItem = ({ item }: { item: Item }) => (
this.props.navigation.navigate(item.routeName)}
/>
);
_keyExtractor = (item: Item) => item.routeName;
render() {
NavigationStackScreenProps,
} from 'react-navigation-stack';
import {
Themed,
createAppContainer,
ThemeColors,
useTheme,
} from 'react-navigation';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { Asset } from 'expo-asset';
import BottomTabs from './src/BottomTabs';
import MaterialTopTabs from './src/MaterialTopTabs';
// Load the back button etc
Asset.loadAsync(StackAssets);
const Home = (props: NavigationStackScreenProps) => {
const theme = useTheme();
return (