Browse Source

Added fullscreen image modal

Arnaud Vergnet 4 years ago
parent
commit
754c43a81a
4 changed files with 88 additions and 20 deletions
  1. 1
    0
      components/Home/FeedItem.js
  2. 5
    4
      package.json
  3. 51
    11
      screens/HomeScreen.js
  4. 31
    5
      screens/Planning/PlanningDisplayScreen.js

+ 1
- 0
components/Home/FeedItem.js View File

4
 import Autolink from "react-native-autolink";
4
 import Autolink from "react-native-autolink";
5
 import i18n from "i18n-js";
5
 import i18n from "i18n-js";
6
 
6
 
7
+
7
 const ICON_AMICALE = require('../../assets/amicale.png');
8
 const ICON_AMICALE = require('../../assets/amicale.png');
8
 
9
 
9
 /**
10
 /**

+ 5
- 4
package.json View File

28
     "@react-navigation/native": "^5.0.9",
28
     "@react-navigation/native": "^5.0.9",
29
     "@react-navigation/stack": "^5.1.1",
29
     "@react-navigation/stack": "^5.1.1",
30
     "expo": "^36.0.0",
30
     "expo": "^36.0.0",
31
+    "expo-linear-gradient": "~8.0.0",
31
     "expo-localization": "~8.0.0",
32
     "expo-localization": "~8.0.0",
32
     "expo-permissions": "~8.0.0",
33
     "expo-permissions": "~8.0.0",
34
+    "expo-secure-store": "~8.0.0",
33
     "expo-web-browser": "~8.0.0",
35
     "expo-web-browser": "~8.0.0",
34
     "i18n-js": "^3.3.0",
36
     "i18n-js": "^3.3.0",
35
     "react": "16.9.0",
37
     "react": "16.9.0",
36
     "react-dom": "16.9.0",
38
     "react-dom": "16.9.0",
37
     "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.1.tar.gz",
39
     "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.1.tar.gz",
38
     "react-native-app-intro-slider": "^3.0.0",
40
     "react-native-app-intro-slider": "^3.0.0",
41
+    "react-native-appearance": "~0.3.1",
39
     "react-native-autolink": "^1.8.1",
42
     "react-native-autolink": "^1.8.1",
40
     "react-native-calendars": "^1.260.0",
43
     "react-native-calendars": "^1.260.0",
41
     "react-native-gesture-handler": "~1.5.0",
44
     "react-native-gesture-handler": "~1.5.0",
45
+    "react-native-image-viewing": "^0.1.8",
42
     "react-native-modalize": "^1.3.6",
46
     "react-native-modalize": "^1.3.6",
43
     "react-native-paper": "^3.6.0",
47
     "react-native-paper": "^3.6.0",
44
     "react-native-reanimated": "~1.4.0",
48
     "react-native-reanimated": "~1.4.0",
45
     "react-native-render-html": "^4.1.2",
49
     "react-native-render-html": "^4.1.2",
46
     "react-native-safe-area-context": "0.6.0",
50
     "react-native-safe-area-context": "0.6.0",
47
     "react-native-screens": "2.0.0-alpha.12",
51
     "react-native-screens": "2.0.0-alpha.12",
48
-    "react-native-webview": "7.4.3",
49
-    "react-native-appearance": "~0.3.1",
50
-    "expo-linear-gradient": "~8.0.0",
51
-    "expo-secure-store": "~8.0.0"
52
+    "react-native-webview": "7.4.3"
52
   },
53
   },
53
   "devDependencies": {
54
   "devDependencies": {
54
     "babel-preset-expo": "^8.0.0",
55
     "babel-preset-expo": "^8.0.0",

+ 51
- 11
screens/HomeScreen.js View File

5
 import i18n from "i18n-js";
5
 import i18n from "i18n-js";
6
 import DashboardItem from "../components/Home/EventDashboardItem";
6
 import DashboardItem from "../components/Home/EventDashboardItem";
7
 import WebSectionList from "../components/Lists/WebSectionList";
7
 import WebSectionList from "../components/Lists/WebSectionList";
8
-import {Text, withTheme} from 'react-native-paper';
8
+import {Portal, Text, withTheme} from 'react-native-paper';
9
 import FeedItem from "../components/Home/FeedItem";
9
 import FeedItem from "../components/Home/FeedItem";
10
 import SquareDashboardItem from "../components/Home/SquareDashboardItem";
10
 import SquareDashboardItem from "../components/Home/SquareDashboardItem";
11
 import PreviewEventDashboardItem from "../components/Home/PreviewEventDashboardItem";
11
 import PreviewEventDashboardItem from "../components/Home/PreviewEventDashboardItem";
12
 import {stringToDate} from "../utils/Planning";
12
 import {stringToDate} from "../utils/Planning";
13
 import {openBrowser} from "../utils/WebBrowser";
13
 import {openBrowser} from "../utils/WebBrowser";
14
+import ImageView from "react-native-image-viewing";
14
 // import DATA from "../dashboard_data.json";
15
 // import DATA from "../dashboard_data.json";
15
 
16
 
16
 
17
 
29
     theme: Object,
30
     theme: Object,
30
 }
31
 }
31
 
32
 
33
+type State = {
34
+    imageModalVisible: boolean,
35
+    imageList: Array<Object>,
36
+}
37
+
32
 /**
38
 /**
33
  * Class defining the app's home screen
39
  * Class defining the app's home screen
34
  */
40
  */
35
-class HomeScreen extends React.Component<Props> {
41
+class HomeScreen extends React.Component<Props, State> {
36
 
42
 
37
     onProxiwashClick: Function;
43
     onProxiwashClick: Function;
38
     onTutorInsaClick: Function;
44
     onTutorInsaClick: Function;
43
 
49
 
44
     colors: Object;
50
     colors: Object;
45
 
51
 
52
+    state = {
53
+        imageModalVisible: false,
54
+        imageList: [],
55
+    };
56
+
46
     constructor(props) {
57
     constructor(props) {
47
         super(props);
58
         super(props);
48
         this.onProxiwashClick = this.onProxiwashClick.bind(this);
59
         this.onProxiwashClick = this.onProxiwashClick.bind(this);
405
         openBrowser(link, this.colors.primary);
416
         openBrowser(link, this.colors.primary);
406
     }
417
     }
407
 
418
 
419
+    showImageModal(imageList) {
420
+        this.setState({
421
+            imageModalVisible: true,
422
+            imageList: imageList,
423
+        });
424
+    };
425
+
426
+    hideImageModal = () => {
427
+        this.setState({imageModalVisible: false});
428
+    };
429
+
430
+
408
     /**
431
     /**
409
      * Gets a render item for the given feed object
432
      * Gets a render item for the given feed object
410
      *
433
      *
412
      * @return {*}
435
      * @return {*}
413
      */
436
      */
414
     getFeedItem(item: Object) {
437
     getFeedItem(item: Object) {
415
-        const onImagePress = this.openLink.bind(this, item.full_picture);
416
         const onOutLinkPress = this.openLink.bind(this, item.permalink_url);
438
         const onOutLinkPress = this.openLink.bind(this, item.permalink_url);
439
+        const imageList = [
440
+            {
441
+                uri: item.full_picture,
442
+            }
443
+        ];
444
+        const onPress = this.showImageModal.bind(this, imageList);
417
         return (
445
         return (
418
             <FeedItem
446
             <FeedItem
419
                 title={NAME_AMICALE}
447
                 title={NAME_AMICALE}
420
                 subtitle={HomeScreen.getFormattedDate(item.created_time)}
448
                 subtitle={HomeScreen.getFormattedDate(item.created_time)}
421
                 full_picture={item.full_picture}
449
                 full_picture={item.full_picture}
422
                 message={item.message}
450
                 message={item.message}
423
-                onImagePress={onImagePress}
424
                 onOutLinkPress={onOutLinkPress}
451
                 onOutLinkPress={onOutLinkPress}
452
+                onImagePress={onPress}
425
             />
453
             />
426
         );
454
         );
427
     }
455
     }
441
     render() {
469
     render() {
442
         const nav = this.props.navigation;
470
         const nav = this.props.navigation;
443
         return (
471
         return (
444
-            <WebSectionList
445
-                createDataset={this.createDataset}
446
-                navigation={nav}
447
-                autoRefreshTime={REFRESH_TIME}
448
-                refreshOnFocus={true}
449
-                fetchUrl={DATA_URL}
450
-                renderItem={this.getRenderItem}/>
472
+            <View>
473
+                <WebSectionList
474
+                    createDataset={this.createDataset}
475
+                    navigation={nav}
476
+                    autoRefreshTime={REFRESH_TIME}
477
+                    refreshOnFocus={true}
478
+                    fetchUrl={DATA_URL}
479
+                    renderItem={this.getRenderItem}/>
480
+                <Portal>
481
+                    <ImageView
482
+                        images={this.state.imageList}
483
+                        imageIndex={0}
484
+                        presentationStyle={"fullScreen"}
485
+                        visible={this.state.imageModalVisible}
486
+                        onRequestClose={this.hideImageModal}
487
+                    />
488
+                </Portal>
489
+            </View>
490
+
451
         );
491
         );
452
     }
492
     }
453
 }
493
 }

+ 31
- 5
screens/Planning/PlanningDisplayScreen.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
 import * as React from 'react';
3
 import * as React from 'react';
4
-import {Image, ScrollView, View} from 'react-native';
4
+import {Image, ScrollView, TouchableOpacity, View} from 'react-native';
5
 import HTML from "react-native-render-html";
5
 import HTML from "react-native-render-html";
6
 import {Linking} from "expo";
6
 import {Linking} from "expo";
7
 import {getDateOnlyString, getFormattedEventTime} from '../../utils/Planning';
7
 import {getDateOnlyString, getFormattedEventTime} from '../../utils/Planning';
8
-import {Card, withTheme} from 'react-native-paper';
8
+import {Card, Portal, withTheme} from 'react-native-paper';
9
 import DateManager from "../../managers/DateManager";
9
 import DateManager from "../../managers/DateManager";
10
+import ImageView from "react-native-image-viewing";
10
 
11
 
11
 type Props = {
12
 type Props = {
12
     navigation: Object,
13
     navigation: Object,
13
     route: Object
14
     route: Object
14
 };
15
 };
15
 
16
 
17
+type State = {
18
+    imageModalVisible: boolean,
19
+};
20
+
16
 function openWebLink(event, link) {
21
 function openWebLink(event, link) {
17
     Linking.openURL(link).catch((err) => console.error('Error opening link', err));
22
     Linking.openURL(link).catch((err) => console.error('Error opening link', err));
18
 }
23
 }
20
 /**
25
 /**
21
  * Class defining a planning event information page.
26
  * Class defining a planning event information page.
22
  */
27
  */
23
-class PlanningDisplayScreen extends React.Component<Props> {
28
+class PlanningDisplayScreen extends React.Component<Props, State> {
24
 
29
 
25
     displayData = this.props.route.params['data'];
30
     displayData = this.props.route.params['data'];
26
 
31
 
27
     colors: Object;
32
     colors: Object;
28
 
33
 
34
+    state = {
35
+        imageModalVisible: false,
36
+    };
37
+
29
     constructor(props) {
38
     constructor(props) {
30
         super(props);
39
         super(props);
31
         this.colors = props.theme.colors;
40
         this.colors = props.theme.colors;
32
     }
41
     }
33
 
42
 
43
+    showImageModal = () => {
44
+        this.setState({imageModalVisible: true});
45
+    };
46
+
47
+    hideImageModal = () => {
48
+        this.setState({imageModalVisible: false});
49
+    };
50
+
34
     render() {
51
     render() {
35
         // console.log("rendering planningDisplayScreen");
52
         // console.log("rendering planningDisplayScreen");
36
         let subtitle = getFormattedEventTime(
53
         let subtitle = getFormattedEventTime(
45
                     subtitle={subtitle}
62
                     subtitle={subtitle}
46
                 />
63
                 />
47
                 {this.displayData.logo !== null ?
64
                 {this.displayData.logo !== null ?
48
-                    <View style={{width: '100%', height: 300}}>
65
+                    <TouchableOpacity onPress={this.showImageModal} style={{width: '100%', height: 300}}>
49
                         <Image style={{flex: 1, resizeMode: "contain"}}
66
                         <Image style={{flex: 1, resizeMode: "contain"}}
50
                                source={{uri: this.displayData.logo}}/>
67
                                source={{uri: this.displayData.logo}}/>
51
-                    </View>
68
+                    </TouchableOpacity>
52
                     : <View/>}
69
                     : <View/>}
53
 
70
 
54
                 {this.displayData.description !== null ?
71
                 {this.displayData.description !== null ?
62
                               onLinkPress={openWebLink}/>
79
                               onLinkPress={openWebLink}/>
63
                     </Card.Content>
80
                     </Card.Content>
64
                     : <View/>}
81
                     : <View/>}
82
+                <Portal>
83
+                    <ImageView
84
+                        images={[{uri: this.displayData.logo}]}
85
+                        imageIndex={0}
86
+                        presentationStyle={"fullScreen"}
87
+                        visible={this.state.imageModalVisible}
88
+                        onRequestClose={this.hideImageModal}
89
+                    />
90
+                </Portal>
65
             </ScrollView>
91
             </ScrollView>
66
         );
92
         );
67
     }
93
     }

Loading…
Cancel
Save