-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nikolay.natorin
committed
May 11, 2021
1 parent
95dfbcf
commit 9caf57d
Showing
13 changed files
with
216 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { useDispatch } from "react-redux"; | ||
|
||
import { acceptInvitation } from './../../actions/correspondents'; | ||
|
||
import { View, Platform, KeyboardAvoidingView, TextInput, Clipboard, TouchableOpacity, Alert } from 'react-native'; | ||
import SafeAreaView from 'react-native-safe-area-view'; | ||
|
||
import Header from '../../components/Header'; | ||
import Button from './../../components/Button'; | ||
import CopyIcon from './../../assets/images/icon-copy.svg'; | ||
|
||
import { REGEX_PAIRING } from "../../lib/messaging"; | ||
|
||
import styles from './styles'; | ||
|
||
const PairInputScreen = ({ navigation, backRoute }) => { | ||
const dispatch = useDispatch(); | ||
const [address, setAddress] = useState(""); | ||
|
||
const onChangeAddress = (value) => { | ||
setAddress(value); | ||
}; | ||
|
||
const handleAddContact = () => { | ||
if (REGEX_PAIRING.test(address)) { | ||
dispatch(acceptInvitation({ data: address })); | ||
} else { | ||
Alert.alert("Warning", "Wrong pairing code"); | ||
} | ||
}; | ||
|
||
const pasteAddress = async () => { | ||
let copiedAddress = await Clipboard.getString(); | ||
setAddress(copiedAddress); | ||
}; | ||
|
||
return ( | ||
<SafeAreaView | ||
style={styles.container} | ||
forceInset={{ top: 'always', bottom: 'always' }} | ||
> | ||
<KeyboardAvoidingView style={styles.content}> | ||
<Header | ||
navigation={navigation} | ||
size='compact' | ||
titlePosition='center' | ||
backRoute={backRoute} | ||
hasBackButton | ||
/> | ||
<View style={styles.addressInputBox}> | ||
<TextInput | ||
style={styles.addressInput} | ||
value={address} | ||
onChangeText={onChangeAddress} | ||
autoCorrect={false} | ||
/> | ||
{!address && ( | ||
<View style={styles.addressInputPaste}> | ||
<TouchableOpacity onPress={pasteAddress}> | ||
<CopyIcon | ||
style={styles.addressInputPasteIcon} | ||
width={19} | ||
height={22} | ||
/> | ||
</TouchableOpacity> | ||
</View> | ||
)} | ||
</View> | ||
<Button | ||
text='Add contact' | ||
onPress={handleAddContact} | ||
style={styles.addButton} | ||
disabled={!address.length} | ||
/> | ||
</KeyboardAvoidingView> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
PairInputScreen.defaultProps = { | ||
backRoute: null, | ||
}; | ||
|
||
PairInputScreen.propTypes = { | ||
backRoute: PropTypes.string, | ||
}; | ||
|
||
export default PairInputScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { StyleSheet } from 'react-native'; | ||
import { colors } from '../../constants'; | ||
|
||
export default StyleSheet.create({ | ||
container: { | ||
backgroundColor: colors.white, | ||
flex: 1, | ||
}, | ||
content: { | ||
paddingHorizontal: 10, | ||
}, | ||
addressInputBox: { | ||
marginTop: 50, | ||
borderRadius: 7, | ||
borderWidth: 2, | ||
borderColor: colors.grey.lightest, | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
addressInput: { | ||
padding: 10, | ||
fontSize: 18, | ||
color: colors.black, | ||
backgroundColor: 'transparent', | ||
flex: 1 | ||
}, | ||
addButton: { | ||
alignSelf: 'center', | ||
marginTop: 40 | ||
}, | ||
addressInputPaste: { | ||
marginLeft: 'auto', | ||
marginRight: 10, | ||
marginVertical: 10 | ||
}, | ||
addressInputPasteIcon: { | ||
marginLeft: 'auto', | ||
color: colors.grey.light | ||
} | ||
}); |
Oops, something went wrong.