Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chat]added snackbar when chat private is exist #555

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/src/services/ethereum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('ethereum', () => {
balance = await ethereum.getTokenBalance('0x9EDCb9A9c4d34b5d6A082c86cb4f117A1394F831');
balance = await ethereum.getOtherBalance('0xF0D346A86A68086846363185d24D5893F4353A78');
balance = await ethereum.getOtherTokenBalance('0x9EDCb9A9c4d34b5d6A082c86cb4f117A1394F831', '0xF0D346A86A68086846363185d24D5893F4353A78');
});
}, 30000);
test('Check nations object', async () => {
const wallet = new ethers.Wallet('0xefc27ba5330258fcfb75e28e4e6efd88458751086998bbfad99257035fb3e160');
wallet.provider = new providers.InfuraProvider('rinkeby');
Expand Down
216 changes: 216 additions & 0 deletions src/components/common/SnackBarComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
View,
TouchableOpacity,
TouchableNativeFeedback,
ViewPropTypes,
Platform,
StyleSheet,
Text,
Animated,
Easing,
} from 'react-native';

const styles = StyleSheet.create({
limit_container: {
position: 'absolute',
overflow: 'hidden',
left: 0,
right: 0,
zIndex: 9999,
},
container: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
position: 'absolute',
zIndex: 9998,
},
text_msg: {
fontSize: 14,
flex: 1,
paddingLeft: 20,
paddingTop: 14,
paddingBottom: 14,
},
action_text: {
fontSize: 14,
fontWeight: '600',
paddingRight: 20,
paddingTop: 14,
paddingBottom: 14,
},
});

const Touchable = ({ onPress, style, children }) => {
if (Platform.OS === 'android' && Platform.Version >= 21) {
return (
<TouchableNativeFeedback
background={TouchableNativeFeedback.SelectableBackgroundBorderless()}
onPress={onPress}
>
<View
style={style}
>
{children}
</View>
</TouchableNativeFeedback>
);
}

return (
<TouchableOpacity
onPress={onPress}
style={style}
>
{children}
</TouchableOpacity>
);
};

Touchable.propTypes = {
onPress: PropTypes.func.isRequired,
style: ViewPropTypes.style,
children: PropTypes.node.isRequired,
};

const easingValues = {
entry: Easing.bezier(0.0, 0.0, 0.2, 1),
exit: Easing.bezier(0.4, 0.0, 1, 1),
};

const durationValues = {
entry: 225,
exit: 195,
};

class SnackbarComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
translateValue: new Animated.Value(0),
hideDistance: 9999,
};
}

componentDidMount() {
if (this.props.visible) {
this.state.translateValue.setValue(1);
} else {
this.state.translateValue.setValue(0);
}
}

componentWillReceiveProps(nextProps) {
if ((nextProps.visible) && (!this.props.visible)) {
Animated.timing(
this.state.translateValue,
{
duration: durationValues.entry,
toValue: 1,
easing: easingValues.entry,
},
).start();
if (nextProps.autoHidingTime) {
const hideFunc = this.hideSnackbar.bind(this);
setTimeout(hideFunc, nextProps.autoHidingTime);
}
} else if ((!nextProps.visible) && (this.props.visible)) {
this.hideSnackbar();
}
}

componentWillUpdate(nextProps, nextState) {
if ((nextProps.visible !== this.props.visible) || (nextState.hideDistance !== this.state.hideDistance)) {
if (nextProps.visible) {
this.props.distanceCallback(nextState.hideDistance + this.props.bottom);
} else {
this.props.distanceCallback(this.props.bottom);
}
}
}

/**
* Starting te animation to hide the snack bar.
* @return {null} No return.
*/
hideSnackbar() {
Animated.timing(
this.state.translateValue,
{
duration: durationValues.exit,
toValue: 0,
easing: easingValues.exit,
},
).start();
}

render() {
return (
<Animated.View
style={[
styles.limit_container,
{
height: this.state.translateValue.interpolate({ inputRange: [0, 1], outputRange: [0, this.state.hideDistance] }),
backgroundColor: this.props.backgroundColor,
},
this.props.position === 'bottom' ? { bottom: this.props.bottom } : { top: this.props.bottom },
]}
>
<Animated.View
style={[
styles.container,
{
backgroundColor: this.props.backgroundColor,
left: this.props.left,
right: this.props.right,
},
this.props.position === 'bottom' ? { bottom: this.state.translateValue.interpolate({ inputRange: [0, 1], outputRange: [this.state.hideDistance * -1, 0] }) } :
{ top: this.state.translateValue.interpolate({ inputRange: [0, 1], outputRange: [this.state.hideDistance * -1, 0] }) },
]}
onLayout={(event) => {
this.setState({ hideDistance: event.nativeEvent.layout.height });
}}
>
<Text style={[styles.text_msg, { color: this.props.messageColor }]}>{this.props.textMessage}</Text>
{this.props.actionHandler && this.props.actionText &&
<Touchable onPress={() => { this.props.actionHandler(); }} >
<Text style={[styles.action_text, { color: this.props.accentColor }]}>{this.props.actionText.toUpperCase()}</Text>
</Touchable>
}
</Animated.View>
</Animated.View>
);
}
}

SnackbarComponent.defaultProps = {
accentColor: 'orange',
messageColor: '#FFFFFF',
backgroundColor: '#484848',
distanceCallback: () => {},
left: 0,
right: 0,
bottom: 0,
position: 'bottom',
autoHidingTime: 0, // Default value will not auto hide the snack bar as the old version.
};

SnackbarComponent.propTypes = {
visible: PropTypes.bool,
actionText: PropTypes.string,
textMessage: PropTypes.string,
accentColor: PropTypes.string,
messageColor: PropTypes.string,
backgroundColor: PropTypes.string,
distanceCallback: PropTypes.func,
actionHandler: PropTypes.func,
left: PropTypes.number,
right: PropTypes.number,
bottom: PropTypes.number,
position: PropTypes.string, // bottom (default), top
autoHidingTime: PropTypes.number, // How long (in milliseconds) the snack bar will be hidden.
};

export default SnackbarComponent;
1 change: 1 addition & 0 deletions src/global/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@
"invalidKey": "Invalid or Missing Key",
"inviteSent": "Invite Sent",
"dAppMessagePreview": "DApp message...",
"alreadyChat": "You already have a chat with this person.",
"chatNameAlert": {
"title": "Enter chat name:",
"confirm": "$t(common.ok)",
Expand Down
47 changes: 42 additions & 5 deletions src/screens/PrivateChat/ChatList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
View,
SectionList,
Share,
Platform,
} from 'react-native';
import _ from 'lodash';
import { Fab, Text } from 'native-base';
Expand All @@ -31,6 +32,7 @@ import { imageSource } from '../../../utils/profile';
import AssetsImages from '../../../global/AssetsImages';
import MoreMenuModal from '../../../components/common/MoreMenuModal';
import type { Contact } from '../../../types/Contacts';
import SnackBar from '../../../components/common/SnackBarComponent';

const MORE_BUTTON = 'MORE_BUTTON';
const MORE_MODAL_KEY = 'moreMenu';
Expand Down Expand Up @@ -93,7 +95,12 @@ type State = {
/**
* @desc List of contacts selected for creating chat.
*/
contacts: Array<Contact>
contacts: Array<Contact>,
/**
* @desc Flag whether snack bar is showing.
*/
showSnackBar: boolean

};

class ChatListScreen extends NavigatorComponent<Props, State> {
Expand All @@ -115,6 +122,7 @@ class ChatListScreen extends NavigatorComponent<Props, State> {
loading: false,
contacts: [],
chatName: '',
showSnackBar: false,
};
}

Expand Down Expand Up @@ -170,16 +178,43 @@ class ChatListScreen extends NavigatorComponent<Props, State> {
});
};

onSelectContacts = (contacts: Array<Contact>) => {
this.props.navigator.dismissModal();

onSelectContacts = async (contacts: Array<Contact>) => {
if (Platform.OS === 'ios') {
await this.props.navigator.dismissModal();
} else {
this.props.navigator.dismissModal();
}
if (contacts.length === 1) {
this.initiateNewChat(contacts, '');
const contact: Contact = contacts[0];
const profiles: ProfileType = contact.profile;
const { identityKey } = profiles;
const chatSelected = this.getChatIdByIdentityKey(identityKey);
if (chatSelected > 0) {
this.setState({ showSnackBar: true });
setTimeout(() => {
this.setState({ showSnackBar: false });
this.onChatSelected(chatSelected);
}, 1000);
} else {
this.initiateNewChat(contacts, '');
}
} else {
this.setState({ contacts, showModal: CHAT_NAME_MODAL });
}
};

getChatIdByIdentityKey = (identityKey: string) => {
const { chats } = this.props;
let chatSelected = -1;
chats.forEach((chat: ChatType) => {
const identityKeyVal = chat.members[0];
if (identityKeyVal === identityKey) {
chatSelected = chat.id;
}
});
return chatSelected;
}

buildChatName = (chat: ChatType) => {
if (chat.name !== null) {
return chat.name;
Expand Down Expand Up @@ -279,7 +314,9 @@ class ChatListScreen extends NavigatorComponent<Props, State> {
onPress={this.dismissModal}
/>
</Dialog.Container>

{this.state.loading === true && <Loading />}
<SnackBar visible={this.state.showSnackBar} textMessage={i18n.t('screens.chat.alreadyChat')} />
</View>
);
}
Expand Down