11import React , { useState , useRef , useEffect } from 'react' ;
2- import { View , Text , StyleSheet } from 'react-native' ;
2+ import { View , Text , StyleSheet , Linking } from 'react-native' ;
33import BetterImage from 'react-native-better-image' ;
44
55const styles = StyleSheet . create ( {
@@ -9,6 +9,9 @@ const styles = StyleSheet.create({
99 justifyContent : 'center' ,
1010 alignItems : 'center' ,
1111 } ,
12+ titleStyle : {
13+ fontWeight : 'bold' ,
14+ } ,
1215} ) ;
1316
1417function useInterval ( callback : ( ) => unknown , delay : number ) {
@@ -32,31 +35,29 @@ function useInterval(callback: () => unknown, delay: number) {
3235 } , [ delay ] ) ;
3336}
3437
38+ const ImageUrl = `https://images.unsplash.com/photo-1610746334198-e7525c63509c?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&h=900` ;
39+ const ThumbnailUrl = `https://images.unsplash.com/photo-1610746334198-e7525c63509c?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&h=90` ;
40+ const placeholderUrl = `https://unsplash.com/a/img/empty-states/photos.png` ;
41+
3542const validSource = {
3643 title : 'Valid Image & Thumbnail' ,
37- image : ( ) =>
38- `https://pyt-images.imgix.net/images/app/pretrip/australia.png?h=346.5&w=252&crop=fit&dpr=3&auto=format,compress,enhance&q=10&bust=${ Math . random ( ) } ` ,
39- thumbnail : ( ) =>
40- `https://pyt-images.imgix.net/images/app/pretrip/australia.png?h=346.5&w=252&crop=fit&dpr=0.1&auto=format,compress,enhance&q=10&bust=${ Math . random ( ) } ` ,
41- placeholder : ( ) => `https://pyt-images.imgix.net/images/place-holder.png` ,
44+ image : ( ) => `${ ImageUrl } &bust=${ Math . random ( ) } ` ,
45+ thumbnail : ( ) => `${ ThumbnailUrl } &bust=${ Math . random ( ) } ` ,
46+ placeholder : ( ) => placeholderUrl ,
4247} ;
4348
4449const inValidSource = {
4550 title : 'Invalid Image & Thumbnail' ,
46- image : ( ) =>
47- `https://pyt-images.imgix.net/images/app/pretrip/nowheretobefound.png?h=346.5&w=252&crop=fit&dpr=0.3&auto=format,compress,enhance&q=10&bust=${ Math . random ( ) } ` ,
48- thumbnail : ( ) =>
49- `https://pyt-images.imgix.net/images/app/pretrip/nowheretobefound.png?h=346.5&w=252&crop=fit&dpr=0.1&auto=format,compress,enhance&q=10&bust=${ Math . random ( ) } ` ,
50- placeholder : ( ) => `https://pyt-images.imgix.net/images/place-holder.png` ,
51+ image : ( ) => `not found` ,
52+ thumbnail : ( ) => `not found` ,
53+ placeholder : ( ) => placeholderUrl ,
5154} ;
5255
5356const invalidImageOnlySource = {
5457 title : 'Invalid Image & Valid Thumbnail' ,
55- image : ( ) =>
56- `https://pyt-images.imgix.net/images/app/pretrip/nowheretobefound.png?h=346.5&w=252&crop=fit&dpr=0.3&auto=format,compress,enhance&q=10&bust=${ Math . random ( ) } ` ,
57- thumbnail : ( ) =>
58- `https://pyt-images.imgix.net/images/app/pretrip/australia.png?h=346.5&w=252&crop=fit&dpr=0.1&auto=format,compress,enhance&q=10&bust=${ Math . random ( ) } ` ,
59- placeholder : ( ) => `https://pyt-images.imgix.net/images/place-holder.png` ,
58+ image : ( ) => `not found` ,
59+ thumbnail : ( ) => `${ ThumbnailUrl } &bust=${ Math . random ( ) } ` ,
60+ placeholder : ( ) => placeholderUrl ,
6061} ;
6162
6263const sources = [ validSource , inValidSource , invalidImageOnlySource ] ;
@@ -82,7 +83,10 @@ function App() {
8283
8384 return (
8485 < View style = { styles . container } >
85- < Text > { imageSource . title } </ Text >
86+ < Text > Various scenarios will change every 5 seconds</ Text >
87+ < Text >
88+ Scenario: < Text style = { styles . titleStyle } > { imageSource . title } </ Text >
89+ </ Text >
8690 < BetterImage
8791 viewStyle = { style }
8892 source = { {
@@ -96,6 +100,30 @@ function App() {
96100 } }
97101 resizeMode = { 'cover' }
98102 />
103+ < Text >
104+ Photo by{ ' ' }
105+ < Text
106+ style = { styles . titleStyle }
107+ onPress = { ( ) =>
108+ Linking . openURL (
109+ 'https://unsplash.com/@vovcarrot?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText'
110+ )
111+ }
112+ >
113+ Vladimir Gladkov
114+ </ Text > { ' ' }
115+ on{ ' ' }
116+ < Text
117+ style = { styles . titleStyle }
118+ onPress = { ( ) =>
119+ Linking . openURL (
120+ 'https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText'
121+ )
122+ }
123+ >
124+ Unsplash
125+ </ Text >
126+ </ Text >
99127 </ View >
100128 ) ;
101129}
0 commit comments