mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
adding image asset control
This commit is contained in:
parent
166ef7ef2c
commit
49f23be418
@ -7,7 +7,7 @@ import { ProfileContext } from 'context/ProfileContext';
|
|||||||
import CryptoJS from 'crypto-js';
|
import CryptoJS from 'crypto-js';
|
||||||
|
|
||||||
export function useConversationContext() {
|
export function useConversationContext() {
|
||||||
const COUNT = 64;
|
const COUNT = 48;
|
||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
loaded: false,
|
loaded: false,
|
||||||
|
@ -31,7 +31,7 @@ export function AudioAsset({ topicId, asset, dismiss }) {
|
|||||||
<Icons name="window-close" size={32} color={Colors.text} />
|
<Icons name="window-close" size={32} color={Colors.text} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<Video ref={player} source={{ uri: state.url }} isLooping={true}
|
<Video ref={player} source={{ uri: state.url }} isLooping={true}
|
||||||
shouldPlay={state.playing} onLoad={actions.loaded} style={styles.player} />
|
paused={!state.playing} onLoad={actions.loaded} style={styles.player} />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,10 @@ export const styles = StyleSheet.create({
|
|||||||
maxHeight: 50,
|
maxHeight: 50,
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
textOverlay: 'center',
|
textAlign: 'center',
|
||||||
|
color: Colors.text,
|
||||||
|
padding: 4,
|
||||||
|
fontSize: 12,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2,14 +2,24 @@ import { View, Image, ActivityIndicator, TouchableOpacity } from 'react-native';
|
|||||||
import { useImageAsset } from './useImageAsset.hook';
|
import { useImageAsset } from './useImageAsset.hook';
|
||||||
import { styles } from './ImageAsset.styled';
|
import { styles } from './ImageAsset.styled';
|
||||||
import Colors from 'constants/Colors';
|
import Colors from 'constants/Colors';
|
||||||
|
import Ionicons from 'react-native-vector-icons/AntDesign';
|
||||||
|
|
||||||
export function ImageAsset({ topicId, asset, dismiss }) {
|
export function ImageAsset({ topicId, asset, dismiss }) {
|
||||||
const { state, actions } = useImageAsset(topicId, asset);
|
const { state, actions } = useImageAsset(topicId, asset);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity style={styles.container} activeOpacity={1}>
|
<TouchableOpacity style={styles.container} activeOpacity={1} onPress={actions.showControls}>
|
||||||
|
{ state.url && (
|
||||||
<Image source={{ uri: state.url }} onLoad={actions.loaded} onError={actions.failed}
|
<Image source={{ uri: state.url }} onLoad={actions.loaded} onError={actions.failed}
|
||||||
style={{ borderRadius: 4, width: state.imageWidth, height: state.imageHeight }} resizeMode={'cover'} />
|
style={{ borderRadius: 4, width: state.imageWidth, height: state.imageHeight }} resizeMode={'cover'} />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{ state.controls && (
|
||||||
|
<TouchableOpacity style={styles.close} onPress={dismiss}>
|
||||||
|
<Ionicons name={'close'} size={32} color={Colors.white} />
|
||||||
|
</TouchableOpacity>
|
||||||
|
)}
|
||||||
|
|
||||||
{ state.failed && (
|
{ state.failed && (
|
||||||
<View style={styles.loading}>
|
<View style={styles.loading}>
|
||||||
<ActivityIndicator color={Colors.alert} size="large" />
|
<ActivityIndicator color={Colors.alert} size="large" />
|
||||||
|
@ -21,5 +21,14 @@ export const styles = StyleSheet.create({
|
|||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
borderColor: Colors.divider,
|
borderColor: Colors.divider,
|
||||||
},
|
},
|
||||||
|
close: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
borderRadius: 4,
|
||||||
|
backgroundColor: Colors.lightgrey,
|
||||||
|
padding: 8,
|
||||||
|
margin: 16,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -14,10 +14,12 @@ export function useImageAsset(topicId, asset) {
|
|||||||
url: null,
|
url: null,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
failed: false,
|
failed: false,
|
||||||
|
controls: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const conversation = useContext(ConversationContext);
|
const conversation = useContext(ConversationContext);
|
||||||
const dimensions = useWindowDimensions();
|
const dimensions = useWindowDimensions();
|
||||||
|
const controls = useRef();
|
||||||
|
|
||||||
const updateState = (value) => {
|
const updateState = (value) => {
|
||||||
setState((s) => ({ ...s, ...value }));
|
setState((s) => ({ ...s, ...value }));
|
||||||
@ -39,6 +41,7 @@ export function useImageAsset(topicId, asset) {
|
|||||||
updateState({ imageWidth: width, imageHeight: height });
|
updateState({ imageWidth: width, imageHeight: height });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
actions.showControls();
|
||||||
}, [state.frameWidth, state.frameHeight, state.imageRatio, state.loaded]);
|
}, [state.frameWidth, state.frameHeight, state.imageRatio, state.loaded]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -58,6 +61,13 @@ export function useImageAsset(topicId, asset) {
|
|||||||
failed: () => {
|
failed: () => {
|
||||||
updateState({ failed: true });
|
updateState({ failed: true });
|
||||||
},
|
},
|
||||||
|
showControls: () => {
|
||||||
|
clearTimeout(controls.current);
|
||||||
|
updateState({ controls: true });
|
||||||
|
controls.current = setTimeout(() => {
|
||||||
|
updateState({ controls: false });
|
||||||
|
}, 2000);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return { state, actions };
|
return { state, actions };
|
||||||
|
Loading…
Reference in New Issue
Block a user