@codeleap/mobile 3.7.1 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "3.7.1",
3
+ "version": "3.9.0",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -2,15 +2,18 @@ import React, { useContext, useState } from 'react'
2
2
  import { deepEqual, onUpdate, ReactState, TypeGuards, usePrevious, useUnmount } from '@codeleap/common'
3
3
 
4
4
  import uuid from 'react-native-uuid'
5
- import { ImageView } from './component'
5
+ import { ImageView, ImageViewProps } from './component'
6
6
  import { ImageProps } from '../Image'
7
7
  import { ImageURISource, ImageRequireSource } from 'react-native'
8
+ import { View } from '../View'
9
+ import { Text } from '../Text'
10
+
8
11
  type ImageSource = ImageURISource | ImageRequireSource
9
12
 
10
13
  type TImage = {
11
- source: ImageSource
12
- created: number
13
- id: string
14
+ source: ImageSource
15
+ created: number
16
+ id: string
14
17
 
15
18
  }
16
19
  type ImageList = Record<string, TImage>
@@ -18,19 +21,18 @@ type ImageList = Record<string, TImage>
18
21
  type SpotlightState = ReactState<Record<string, ImageList>>
19
22
  type IndexState = ReactState<Record<string, number>>
20
23
  type TSpotlightCtx = {
21
- spotlights: SpotlightState[0]
22
- setSpotlights: SpotlightState[1]
23
- indexes: IndexState[0]
24
- setIndexes: IndexState[1]
25
-
24
+ spotlights: SpotlightState[0]
25
+ setSpotlights: SpotlightState[1]
26
+ indexes: IndexState[0]
27
+ setIndexes: IndexState[1]
26
28
  }
27
29
 
28
30
  const SpotlightCtx = React.createContext({} as TSpotlightCtx)
29
31
 
30
- export const SpotlightProvider:React.FC<React.PropsWithChildren<any>> = ({ children }) => {
32
+ export const SpotlightProvider: React.FC<React.PropsWithChildren<any>> = ({ children }) => {
31
33
  const [spotlights, setSpotlights] = useState<TSpotlightCtx['spotlights']>({})
32
34
  const [indexes, setIndexes] = useState<TSpotlightCtx['indexes']>({})
33
- const ctxValue:TSpotlightCtx = {
35
+ const ctxValue: TSpotlightCtx = {
34
36
  spotlights,
35
37
  setSpotlights,
36
38
  indexes,
@@ -143,17 +145,48 @@ export const useImageSpotlight = (name: string | null, src: ImageProps['source']
143
145
  }
144
146
  }
145
147
 
146
- export const Spotlight = ({ name }: {name: string}) => {
148
+ type HeaderComponentProps = {
149
+ imageIndex: number
150
+ spotlight: ReturnType<typeof useSpotlight>
151
+ }
152
+
153
+ type DefaultFooterComponentType = React.ComponentType<{
154
+ imageIndex: number
155
+ imagesLength: number
156
+ }>
157
+
158
+ type FooterComponentProps = HeaderComponentProps
159
+
160
+ type SpotlightProps = {
161
+ name?: string
162
+ HeaderComponent?: (props: HeaderComponentProps) => JSX.Element
163
+ FooterComponent?: (props: FooterComponentProps) => JSX.Element
164
+ showFooter?: boolean
165
+ } & ImageViewProps
166
+
167
+ const DefaultFooterComponent: DefaultFooterComponentType = ({ imageIndex, imagesLength }) => (
168
+ <View variants={['marginBottom:5', 'alignCenter']}>
169
+ <Text text={imageIndex + 1 + '/' + imagesLength} />
170
+ </View>
171
+ )
172
+
173
+ export const Spotlight: React.FC<SpotlightProps> = ({ name, HeaderComponent, FooterComponent, ...rest }) => {
147
174
  const spotlight = useSpotlight(name)
148
175
  useUnmount(() => {
149
176
  spotlight.clear()
150
177
  })
178
+
151
179
  return <ImageView
152
180
  imageIndex={spotlight.currentIndex}
153
181
  images={spotlight.images.map(x => x.source)}
154
182
  keyExtractor={(_, index) => index.toString()}
155
183
  onRequestClose={spotlight.close}
156
184
  visible={typeof spotlight.currentIndex !== 'undefined'}
157
-
185
+ {...rest}
186
+ FooterComponent={({ imageIndex }) => !!FooterComponent ?
187
+ <FooterComponent imageIndex={imageIndex} spotlight={spotlight} /> :
188
+ <DefaultFooterComponent imageIndex={imageIndex} imagesLength={spotlight.images.length} />
189
+ }
190
+ HeaderComponent={!!HeaderComponent ? ({ imageIndex }) => <HeaderComponent spotlight={spotlight} imageIndex={imageIndex} /> : undefined}
158
191
  />
159
192
  }
@@ -3,22 +3,8 @@ import * as React from 'react'
3
3
  import { onUpdate, PropsOf } from '@codeleap/common'
4
4
  import _ImageView from 'react-native-image-viewing'
5
5
  import { StatusBar } from 'react-native'
6
- import { View } from '../View'
7
- import { Text } from '../Text'
8
-
9
- type FooterComponentType = React.ComponentType<{
10
- imageIndex: number
11
- imagesLength: number
12
- }>
13
-
14
- const FooterComponent: FooterComponentType = ({ imageIndex, imagesLength }) => (
15
- <View variants={['marginBottom:5', 'alignCenter']}>
16
- <Text text={imageIndex + 1 + '/' + imagesLength}/>
17
- </View>
18
- )
19
6
 
20
7
  export type ImageViewProps = PropsOf<typeof _ImageView>
21
-
22
8
  export const ImageView: React.FC<ImageViewProps> = (props) => {
23
9
  onUpdate(() => {
24
10
  StatusBar.setHidden(props.visible)
@@ -27,7 +13,6 @@ export const ImageView: React.FC<ImageViewProps> = (props) => {
27
13
  return (
28
14
  <_ImageView
29
15
  doubleTapToZoomEnabled={false}
30
- FooterComponent={({ imageIndex }) => <FooterComponent imageIndex={imageIndex} imagesLength={props.images.length}/>}
31
16
  presentationStyle={'overFullScreen'}
32
17
  {...props}
33
18
  />