react-native#Share JavaScript Examples
The following examples show how to use
react-native#Share.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SharePlay.js From UltimateApp with MIT License | 6 votes |
SharePlay = ({ currentPlay }) => {
const share = async () => {
try {
const shareUuid = await upload('customPlays', currentPlay);
const url = await createLink('custom/plays/' + shareUuid, currentPlay.title);
await Share.share({
title: I18n.t('editor.sharePlay.shareTitle', { title: currentPlay.title }),
message: I18n.t('editor.sharePlay.shareMessage', { url }),
url,
});
} catch (error) {
showError(I18n.t('editor.sharePlay.shareError'));
}
};
return (
<TouchableOpacity onPress={share} testID="shareButton">
<Ionicons
name={Platform.select({
ios: 'ios-share-outline',
default: 'share-social-outline',
})}
color={theme.COLOR_PRIMARY_LIGHT}
size={30}
/>
</TouchableOpacity>
);
}
Example #2
Source File: SharePlay.test.js From UltimateApp with MIT License | 6 votes |
describe('<SharePlay />', () => {
afterEach(() => jest.clearAllMocks());
const currentPlay = { animation: animationSquare, title: 'Square', uuid: '123' };
it('renders correctly', async () => {
const { toJSON } = await waitFor(() => render(<SharePlay currentPlay={currentPlay} />));
expect(toJSON()).toMatchSnapshot();
});
it('triggers share action', async () => {
jest.spyOn(firebase, 'upload').mockImplementation(() => 'uuid');
jest.spyOn(firebase, 'createLink').mockImplementation(() => '');
const share = jest.fn();
Share.share = () => new Promise((resolve, reject) => share());
const { getByTestId } = await waitFor(() => render(<SharePlay currentPlay={currentPlay} />));
fireEvent.press(getByTestId('shareButton'));
await expect(firebase.upload).toHaveBeenCalledWith('customPlays', currentPlay);
await expect(firebase.createLink).toHaveBeenCalledWith('custom/plays/uuid', currentPlay.title);
expect(share).toHaveBeenCalled();
});
});
Example #3
Source File: VideoPage.test.js From UltimateApp with MIT License | 6 votes |
describe('<VideoPage />', () => {
const route = {
params: {
video: store.getState().theory.essentials[0].pages[0],
},
};
// fake NavigationContext value data
const navContext = {
isFocused: () => true,
// addListener returns an unscubscribe function.
addListener: jest.fn(() => jest.fn()),
};
it('renders correctly', () => {
const { toJSON } = render(
<NavigationContext.Provider value={navContext}>
<VideoPage route={route} />
</NavigationContext.Provider>,
);
expect(toJSON()).toMatchSnapshot();
});
it('triggers share', async () => {
const share = jest.fn();
Share.share = () => new Promise((resolve, reject) => share());
const { getByTestId } = render(
<NavigationContext.Provider value={navContext}>
<VideoPage route={route} />
</NavigationContext.Provider>,
);
await fireEvent.press(getByTestId('shareButton'));
expect(share).toHaveBeenCalled();
});
});
Example #4
Source File: PostHandlers.js From Cosmos with MIT License | 6 votes |
onShare = (id, setError) => {
Share.share({
title: 'Cosmos Post',
message: `Cosmos link:- https://cosmosrn.now.sh/link/post?id=${id}`,
}).catch((err) => {
console.log('Error at onShare:', err.message);
setError(err.message);
});
}
Example #5
Source File: ShareDrill.js From UltimateApp with MIT License | 5 votes |
ShareDrill = ({ drill, light }) => {
const share = async () => {
const url = await createLink(
'drills/' + drill.id,
drill.title,
I18n.t('drills.shareDrill.description', { description: drill.description.slice(0, 70) }),
);
const youtubeVideos = drill.steps.reduce((total, step) => {
const stepvideo = step.youtube ? `${step.title} - ${step.youtube}\n` : '';
return total + stepvideo;
}, '');
Share.share({
title: I18n.t('drills.shareDrill.title', { drillTitle: drill.title }),
message: I18n.t('drills.shareDrill.content', { url, youtubeVideos, count: youtubeVideos.length }),
url,
}).catch((error) => showError(I18n.t('drills.shareDrill.error')));
};
const shareCustom = async () => {
try {
const shareUuid = await upload('customDrills', drill);
const url = await createLink('custom/drills/' + shareUuid, drill.title);
await Share.share({
title: I18n.t('drills.shareDrill.title', { title: drill.title }),
message: I18n.t('drills.shareDrill.content', { url, count: 0 }),
url,
});
} catch (error) {
showError(I18n.t('drills.shareDrill.error'));
}
};
const lightColor = light ? styles.lightColor : undefined;
return (
<TouchableOpacity onPress={drill.custom ? shareCustom : share} testID="shareButton">
<Ionicons
name={Platform.select({
ios: 'ios-share-outline',
default: 'share-social',
})}
style={[styles.icon, lightColor]}
/>
</TouchableOpacity>
);
}
Example #6
Source File: ShareDrill.test.js From UltimateApp with MIT License | 5 votes |
describe('<ShareDrill />', () => {
afterEach(() => jest.clearAllMocks());
const drill = store.getState().drills[0];
it('renders correctly', async () => {
const { toJSON } = await waitFor(() => render(<ShareDrill drill={drill} />));
expect(toJSON()).toMatchSnapshot();
});
it('renders correctly when light', async () => {
const { toJSON } = await waitFor(() => render(<ShareDrill drill={drill} light />));
expect(toJSON()).toMatchSnapshot();
});
it('triggers share action for an app drill', async () => {
jest.spyOn(firebase, 'createLink').mockImplementation(() => '');
const share = jest.fn();
Share.share = () => new Promise((resolve, reject) => share());
const { getByTestId } = await waitFor(() => render(<ShareDrill drill={drill} />));
fireEvent.press(getByTestId('shareButton'));
await expect(firebase.createLink).toHaveBeenCalledWith('drills/' + drill.id, drill.title, expect.any(String));
expect(share).toHaveBeenCalled();
});
it('triggers share action for a custom drill', async () => {
const customDrill = createDrill({ id: 2, custom: true });
jest.spyOn(firebase, 'upload').mockImplementation(() => 'uuid');
jest.spyOn(firebase, 'createLink').mockImplementation(() => '');
const share = jest.fn();
Share.share = () => new Promise((resolve, reject) => share());
const { getByTestId } = await waitFor(() => render(<ShareDrill drill={customDrill} />));
fireEvent.press(getByTestId('shareButton'));
await expect(firebase.upload).toHaveBeenCalledWith('customDrills', customDrill);
await expect(firebase.createLink).toHaveBeenCalledWith('custom/drills/uuid', customDrill.title);
expect(share).toHaveBeenCalled();
});
});
Example #7
Source File: VideoPage.js From UltimateApp with MIT License | 5 votes |
VideoPage = (props) => {
const video = props.route.params.video;
const share = () => {
const url = video.youtube;
Share.share({
message: I18n.t('videoPage.shareContent', { url }),
url,
}).catch((e) => {
showError(I18n.t('videoPage.error'));
});
};
return (
<View style={styles.videoPage}>
<View style={styles.video}>
<VimeoVideo vimeoId={video.video} sounds shouldPlay />
</View>
<View style={styles.title}>
<Text style={styles.text}>{video.title}</Text>
<Text style={styles.textAuthor}>{video.text}</Text>
</View>
{video.youtube && (
<View style={styles.footer}>
<Button
onPress={share}
icon={Platform.select({
ios: 'ios-share-outline',
default: 'share-social',
})}
text={I18n.t('videoPage.share')}
testID="shareButton"
small
light
/>
</View>
)}
</View>
);
}
Example #8
Source File: use-share.js From astrale with GNU General Public License v3.0 | 5 votes |
useShare = (message, url) => {
const [startShare, setStartShare] = React.useState(false);
React.useEffect(() => {
const sharing = async () => {
try {
const buildContent = () => {
const content = {};
if (PlatformUtils.isIos) {
content.message = message;
content.url = url;
} else {
content.message = url;
content.title = message;
}
return content;
};
const content = buildContent();
const result = await Share.share(content);
if (result.action === Share.sharedAction) {
if (result.activityType) {
// shared with activity type of result.activityType
} else {
// shared
}
} else if (result.action === Share.dismissedAction) {
// dismissed
}
} catch (error) {
// todo
}
return true;
};
if (startShare) {
sharing().then(() => setStartShare(false));
}
}, [startShare]);
return { setStartShare };
}
Example #9
Source File: InviteScreen.js From filen-mobile with GNU Affero General Public License v3.0 | 4 votes |
InviteScreen = memo(({ navigation, route }) => {
const [darkMode, setDarkMode] = useMMKVBoolean("darkMode", storage)
const [lang, setLang] = useMMKVString("lang", storage)
const [isLoading, setIsLoading] = useState(true)
const [accountData, setAccountData] = useState({})
const isMounted = useMountedState()
useEffect(() => {
getAccount().then((data) => {
if(isMounted()){
setAccountData(data)
setIsLoading(false)
}
}).catch((err) => {
console.log(err)
showToast({ message: err.toString() })
})
}, [])
return (
<>
<View style={{
flexDirection: "row",
justifyContent: "flex-start",
backgroundColor: darkMode ? "black" : "white"
}}>
<TouchableOpacity style={{
marginTop: Platform.OS == "ios" ? 17 : 4,
marginLeft: 15,
}} onPress={() => navigation.goBack()}>
<Ionicon name="chevron-back" size={24} color={darkMode ? "white" : "black"}></Ionicon>
</TouchableOpacity>
<Text style={{
color: darkMode ? "white" : "black",
fontWeight: "bold",
fontSize: 24,
marginLeft: 10,
marginTop: Platform.OS == "ios" ? 15 : 0
}}>
{i18n(lang, "invite")}
</Text>
</View>
<ScrollView style={{
height: "100%",
width: "100%",
backgroundColor: darkMode ? "black" : "white"
}}>
{
isLoading ? (
<ActivityIndicator size={"small"} color={darkMode ? "white" : "black"} style={{
marginTop: "70%"
}} />
) : (
<>
<SettingsGroup>
<View style={{
width: "100%",
height: "auto"
}}>
<View style={{
width: "100%",
height: "auto",
flexDirection: "row",
justifyContent: "space-between",
paddingLeft: 10,
paddingRight: 10,
paddingTop: 10,
paddingBottom: 10
}}>
<View>
<Text style={{
color: darkMode ? "white" : "black"
}}>
{i18n(lang, "inviteInfo")}
</Text>
</View>
</View>
</View>
</SettingsGroup>
<SettingsGroup>
<View style={{
width: "100%",
height: "auto"
}}>
<View style={{
width: "100%",
height: "auto",
flexDirection: "row",
justifyContent: "space-between",
paddingLeft: 10,
paddingRight: 10,
paddingTop: 10,
paddingBottom: 10
}}>
<View>
<Text style={{
color: darkMode ? "white" : "black"
}}>
{i18n(lang, "inviteCount")}
</Text>
</View>
<Text style={{
color: darkMode ? "white" : "black"
}}>
{accountData.referCount > accountData.refLimit ? accountData.refLimit : accountData.referCount}/{accountData.refLimit}
</Text>
</View>
</View>
</SettingsGroup>
<SettingsGroup>
<Pressable style={{
width: "100%",
height: "auto"
}} onPress={() => {
Clipboard.setString("https://filen.io/r/" + accountData.refId)
showToast({ message: i18n(lang, "copiedToClipboard") })
}}>
<View style={{
width: "100%",
height: "auto",
flexDirection: "row",
justifyContent: "space-between",
paddingLeft: 10,
paddingRight: 10,
paddingTop: 10,
paddingBottom: 10
}}>
<Text style={{
color: darkMode ? "white" : "black",
width: "70%"
}} numberOfLines={1}>
https://filen.io/r/{accountData.refId}
</Text>
<TouchableOpacity onPress={() => {
Share.share({
message: i18n(lang, "shareRefLinkMessage"),
url: "https://filen.io/r/" + accountData.refId
})
}}>
<Text style={{
color: "#0A84FF"
}}>
{i18n(lang, "share")}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => {
Clipboard.setString("https://filen.io/r/" + accountData.refId)
showToast({ message: i18n(lang, "copiedToClipboard") })
}}>
<Text style={{
color: "#0A84FF"
}}>
{i18n(lang, "copy")}
</Text>
</TouchableOpacity>
</View>
</Pressable>
</SettingsGroup>
<View style={{
width: "100%",
height: "auto",
paddingLeft: 8,
paddingRight: 8,
marginTop: 5
}}>
<View style={{
width: "100%",
height: "auto",
flexDirection: "row",
justifyContent: "space-between",
paddingLeft: 10,
paddingRight: 10,
paddingTop: 10,
paddingBottom: 10
}}>
<View>
<Text style={{
color: "gray",
fontSize: 10
}}>
{i18n(lang, "inviteInfo2")}
</Text>
</View>
</View>
</View>
</>
)
}
</ScrollView>
</>
)
})
Example #10
Source File: IncognitoSearch.js From Turbo-Browser with MIT License | 4 votes |
IncognitoSearch = ({ navigation, route }) => {
const styleTypes = ['default','dark-content', 'light-content'];
const [styleStatusBar, setStyleStatusBar] = useState(styleTypes[2]);
const [rippleOverflow, setRippleOverflow] = useState(false);
const [canGoBack, setCanGoBack] = useState(false);
const [canGoForward, setCanGoForward] = useState(false);
const [currentUrl, setCurrentUrl] = useState("");
const [WebL, setWebL] = useState(true);
const [cUrl, setCUrl] = useState((route.params.name).replace("turbo/", ""));
const [httpS, setHttpS] = useState(2);
const [favIcon, setFavIcon] = useState("");
const [webTS, setWebTS] = useState((route.params.name).replace("turbo/", "").split("/")[2] > 26 ? cUrl.split("/")[2].substring(0, 24) + "..." : cUrl.split("/")[2]);
const [webViewShow, setWebViewShow] = useState(false);
const [fullscreen, setFullscreen] = useState(false);
const [f2, setF2] = useState(false);
const BottomNavOpacity = useRef(new Animated.Value(1)).current;
const [optionsAlertOpen, setOptionsAlertOpen] = useState(false);
const [searchAlertOpen, setSearchAlertOpen] = useState(false);
const INJECTEDJAVASCRIPT = `
const meta = document.createElement('meta'); meta.setAttribute('content', 'initial-scale=1.0, maximum-scale=1.0'); meta.setAttribute('name', 'viewport'); document.getElementsByTagName('head')[0].appendChild(meta);
var links = document.links, i, length;
for (i = 0, length = links.length; i < length; i++) {
links[i].target == '_blank' && links[i].removeAttribute('target');
}
window.ReactNativeWebView.postMessage(document.title);
`;
const inputRef = React.useRef();
const webviewRef = useRef(null);
const [searchOpen, setSearchOpen] = useState(false);
const [searchValue, setSearchValue] = useState("");
const [bookmarksKeyValue, setBookmarksKeyValue] = useState("");
const appInfo = useSelector((state) => state.appInfo);
useEffect(() => {
Keyboard.addListener("keyboardDidShow", _keyboardDidShow);
Keyboard.addListener("keyboardDidHide", _keyboardDidHide);
// cleanup function
return () => {
Keyboard.removeListener("keyboardDidShow", _keyboardDidShow);
Keyboard.removeListener("keyboardDidHide", _keyboardDidHide);
};
}, []);
const speechToTextHandler = async () => {
showToast4();
}
const _keyboardDidShow = () => {
if(route.name == "IncognitoSearch"){
setF2(true);
} else {
// Do nothing
}
};
const _keyboardDidHide = () => {
if(route.name == "IncognitoSearch"){
setF2(false);
} else {
// Do nothing
}
};
const showToast = () => {
ToastAndroid.show("URL copied", ToastAndroid.SHORT);
};
const showToast2 = () => {
ToastAndroid.show("You can't set bookmarks on Incognito mode", ToastAndroid.SHORT);
};
const showToast4 = () => {
ToastAndroid.show("You can't use Voice Search on Incognito mode", ToastAndroid.SHORT);
};
useEffect(() => {
setTimeout(() => {
setWebViewShow(true);
}, 100);
}, [])
const se1 = () => {
if (webviewRef.current){
if(canGoBack) {
webviewRef.current.goBack();
} else {
navigation.goBack();
}
}
}
const se2 = () => {
if (webviewRef.current) webviewRef.current.goForward();
}
const se3 = () => {
navigation.navigate('Home', { name: "Home" });
}
const setHttpIcon = () => {
if(cUrl.substring(0, 5) == "https") {
setHttpS(1);
} else if (cUrl.substring(0, 5) == "http:") {
setHttpS(2);
} else {
setHttpS(3);
}
}
useEffect(() => {
navigation.addListener('focus',
() => {
let urlToOpen = (route.params.name).replace("turbo/", "");
setCurrentUrl(urlToOpen);
setWebTS(urlToOpen.split("/")[2] > 26 ? cUrl.split("/")[2].substring(0, 24) + "..." : cUrl.split("/")[2]);
setHttpS(2);
setF2(false);
}
);
}, []);
const refreshWeb = () => {
if (webviewRef.current) webviewRef.current.reload();
}
const handleFullScrTouch = () => {
if(fullscreen){
setFullscreen(false);
Animated.timing(
BottomNavOpacity,
{
toValue: 0,
duration: 0,
useNativeDriver: true,
}
).start();
setTimeout(() => {
Animated.timing(
BottomNavOpacity,
{
toValue: 1,
duration: 200,
useNativeDriver: true,
}
).start();
}, 200);
} else {
setFullscreen(true);
Animated.timing(
BottomNavOpacity,
{
toValue: 0,
duration: 100,
useNativeDriver: true,
}
).start();
}
}
const se4 = () => {
showToast2();
}
const se5 = () => {
setOptionsAlertOpen(true);
}
const onShare = async () => {
try {
const result = await Share.share({
message: currentUrl,
});
if (result.action === Share.sharedAction) {
if (result.activityType) {
// shared with activity type of result.activityType
} else {
// shared
}
} else if (result.action === Share.dismissedAction) {
// dismissed
}
} catch (error) {
// error
}
};
const copyToClipboard = () => {
Clipboard.setString(currentUrl);
};
const onSearchChangeText = (text) => {
setSearchValue(text);
}
const searchStringS = (string) => {
if(string == ""){
} else if (string.substring(0, 8) == "https://" || string.substring(0, 7) == "http://") {
setCurrentUrl(string);
} else {
setCurrentUrl("https://duckduckgo.com/?q=" + string.replace(/ /g,"+"));
}
}
const voiceSearchBtnClk = () => {
speechToTextHandler();
setSearchAlertOpen(false);
setSearchOpen(false);
}
const se4Remove = async () => {
showToast2();
}
useEffect(() => {
navigation.addListener('focus',
() => {
changeNavigationBarColor("#1C2124", false, true);
}
);
navigation.addListener('blur',
() => {
changeNavigationBarColor("#FFFFFF", true, true);
}
);
}, []);
return (
<SafeAreaView>
<StatusBar backgroundColor="#1C2124FF" barStyle={styleStatusBar} />
<Modal
isOpen={searchAlertOpen}
onClosed={() => {
setSearchAlertOpen(false);
setSearchOpen(false);
}}
style={[styles.modal, styles.modal12]}
entry={"top"}
position={"top"}
backdropPressToClose={true}
swipeToClose={false}
backdropOpacity={0.6}
backButtonClose={true}
coverScreen={false}
animationDuration={200}
>
<View style={styles.view__2}>
<View style={{borderRadius: 40, overflow: 'hidden'}}>
{/* <TouchableOpacity
style={{width: "100%"}}
> */}
<View style={styles.view_input_c_1}>
<IonicIcon style={styles.search_icon} name="search"/>
<TextInput
ref={inputRef}
style={{
// maxWidth: 200,
fontSize: 14,
color: "#808D8FFE",
marginLeft: 8,
fontFamily: "Helvetica",
flexGrow: 1,
}}
value={searchValue}
onChangeText={(text) => onSearchChangeText(text)}
autoFocus={true}
editable={searchOpen}
onSubmitEditing={() => {
setSearchAlertOpen(false);
setSearchOpen(false);
searchStringS(searchValue);
}}
placeholderTextColor="#4A5558FE"
placeholder="Search DuckDuckGo"
/>
{
searchValue.length > 0 ?
<IonicIcon onPress={() => setSearchValue("")} style={styles.mic_icon} name="close"/>
:
<></>
}
</View>
{/* </TouchableOpacity> */}
</View>
</View>
</Modal>
<Modal
isOpen={optionsAlertOpen}
onClosed={() => {setOptionsAlertOpen(false)}}
style={[styles.modal, styles.modal8]}
position={"bottom"}
backdropPressToClose={true}
swipeToClose={false}
backdropOpacity={0.6}
backButtonClose={true}
coverScreen={false}
animationDuration={200}
>
<View style={styles.optionAlertCont_MAIN}>
<View style={styles.optionAlertCont_opt_1}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
copyToClipboard();
showToast();
}}>
<Text style={styles.optionAlertCont_optText_1}>
Copy URL
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_1}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
setTimeout(() => {
onShare();
}, 320);
}}>
<Text style={styles.optionAlertCont_optText_1}>
Share
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_1}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
setCurrentUrl("view-source:" + currentUrl);
}}>
<Text style={styles.optionAlertCont_optText_1}>
View page source
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_1_B}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
navigation.navigate('Home', { name: "Incognito" });
}}>
<Text style={styles.optionAlertCont_optText_1}>
Close Incognito
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_icon_1}>
<TouchableOpacity style={{
width: "100%",
display: "flex",
alignItems: "center",
justifyContent: "center",
paddingBottom: 10,
marginBottom: 4,
}} onPress={() => {setOptionsAlertOpen(false)}}>
{/* <FontAwesome style={styles.optionAlertCont_opt_icon_2} name="chevron-down"/> */}
<Image
source={require("../assets/arrowDown2.png")}
style={{
height: 26,
width: 26,
}}
/>
</TouchableOpacity>
</View>
</View>
</Modal>
<View style={styles.searchMainContainer}>
{/* Search 1 */}
<View style={styles.search_1}>
{
currentUrl.includes("view-source:") ?
<View style={styles.sea1__1}>
<Image
style={styles.sea1__1A}
source={( favIcon.includes("https://api.statvoo.com/favicon/?url=https://www.google.com/") ? require("../assets/googleIcon.png") :
{uri: favIcon})}
/>
</View>
:
<View style={styles.sea1__1}>
{WebL ?
<ActivityIndicator size="small" style={{
height: 16,
width: 16,
resizeMode: "cover",
marginLeft: 8,
marginRight: 8,
}} color={'#4A5558FE'} />
:
<Image
style={styles.sea1__1A}
source={(favIcon.includes("https://api.statvoo.com/favicon/?url=https://www.nytimes.com/") ? require("../assets/ny.png") :
favIcon.includes("https://api.statvoo.com/favicon/?url=https://www.google.com/") ? require("../assets/googleIcon.png") :
{uri: favIcon})}
/>
}
</View>
}
<View style={{
height: 30,
borderRadius: 30,
flexGrow: 1,
overflow: "hidden",
}}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AEAEAEFF", rippleOverflow)}
onPress={() => {
setSearchAlertOpen(true);
setSearchValue("");
setTimeout(() => {
setSearchOpen(true);
inputRef.current?.focus();
}, 400);
}}
>
<View style={styles.sea1__2}>
<View style={styles.sea1__2A}>
{
(httpS == 1) ?
<MaterialIcons style={styles.sea1__2A_icon1} name="https"/>
: (httpS == 2) ?
<MaterialIcons style={styles.sea1__2A_icon2} name="https"/>
: (httpS == 3) ?
<MaterialIcons style={styles.sea1__2A_icon2} name="https"/>
: <MaterialIcons style={styles.sea1__2A_icon2} name="https"/>
}
</View>
<View style={styles.sea1__2B}>
<Text style={styles.sea1__2B_txt}>
{currentUrl.replace("turbo/", "").split("/")[2] > 26 ? cUrl.split("/")[2].substring(0, 24) + "..." : cUrl.split("/")[2]}
</Text>
</View>
<TouchableOpacity onPress={refreshWeb}>
<View style={styles.sea1__2C}>
<MaterialIcons style={styles.sea1__2C_icon} name="replay"/>
</View>
</TouchableOpacity>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.sea1__3}>
<TouchableOpacity onPress={handleFullScrTouch}>
{/* <MaterialIcons style={styles.sea1__3_icon} name="more-vert"/> */}
{
fullscreen ?
<MaterialIcons style={styles.sea1__3_icon} name="fullscreen-exit"/>
:
<MaterialIcons style={styles.sea1__3_icon} name="fullscreen"/>
}
</TouchableOpacity>
</View>
</View>
{/* Search 2 */}
<View style={styles.search_2}>
{
webViewShow ?
<WebView
startInLoadingState={true}
ref={webviewRef}
source={{
uri: currentUrl,
}}
onNavigationStateChange={navState => {
setCanGoBack(navState.canGoBack);
setCanGoForward(navState.canGoForward);
setCUrl(navState.url);
// setWebTS(cUrl.split("/")[2] > 26 ? cUrl.split("/")[2].substring(0, 24) + "..." : cUrl.split("/")[2]);
}}
allowFileAccess={true}
geolocationEnabled={true}
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
injectedJavaScript={INJECTEDJAVASCRIPT}
onLoadStart={() => {
setWebL(true);
}}
onLoadEnd={() => {
setFavIcon("https://api.statvoo.com/favicon/?url=" + cUrl);
setWebL(false);
setHttpIcon();
setWebTS(cUrl.split("/")[2] > 26 ? cUrl.split("/")[2].substring(0, 24) + "..." : cUrl.split("/")[2]);
}}
userAgent="Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36"
domStorageEnabled={false}
/>
: <></>
}
</View>
{/* Search 3 */}
{
fullscreen || f2 ?
<></>
:
<Animated.View
style={{
opacity: BottomNavOpacity
}}
>
<View style={styles.search_3}>
<TouchableOpacity onPress={se1} style={styles.sea_3_item}>
<View>
<IonicIcon style={styles.sea3__3_icon} name="chevron-back-outline"/>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={se2} style={styles.sea_3_item}>
<View>
<IonicIcon style={styles.sea3__3_icon} name="chevron-forward-outline"/>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={se3} style={styles.sea_3_item}>
<View>
<IonicIcon style={styles.sea3__3_icon} name="home-outline"/>
</View>
</TouchableOpacity>
{
bookmarksKeyValue.includes(currentUrl) ?
<TouchableOpacity onPress={se4Remove} style={styles.sea_3_item}>
<View>
<IonicIcon style={styles.sea3__3_icon_r} name="heart"/>
</View>
</TouchableOpacity>
:
<TouchableOpacity onPress={se4} style={styles.sea_3_item}>
<View>
<IonicIcon style={styles.sea3__3_icon_r} name="heart-outline"/>
</View>
</TouchableOpacity>
}
<TouchableOpacity onPress={se5} style={styles.sea_3_item}>
<View>
<IonicIcon style={styles.sea3__3_icon} name="grid-outline"/>
</View>
</TouchableOpacity>
</View>
</Animated.View>
}
</View>
</SafeAreaView>
);
}
Example #11
Source File: Search.js From Turbo-Browser with MIT License | 4 votes |
Search = ({ navigation, route }) => {
const styleTypes = ['default','dark-content', 'light-content'];
const [styleStatusBar, setStyleStatusBar] = useState(styleTypes[1]);
const [rippleOverflow, setRippleOverflow] = useState(false);
const [canGoBack, setCanGoBack] = useState(false);
const [canGoForward, setCanGoForward] = useState(false);
const [currentUrl, setCurrentUrl] = useState("");
const [WebL, setWebL] = useState(true);
const [cUrl, setCUrl] = useState((route.params.name).replace("turbo/", ""));
const [httpS, setHttpS] = useState(2);
const [favIcon, setFavIcon] = useState("");
const [webTS, setWebTS] = useState((route.params.name).replace("turbo/", "").split("/")[2] > 26 ? cUrl.split("/")[2].substring(0, 24) + "..." : cUrl.split("/")[2]);
const [titleCurrent, setTitleCurrent] = useState("");
const [webViewShow, setWebViewShow] = useState(false);
const [fullscreen, setFullscreen] = useState(false);
const [f2, setF2] = useState(false);
const BottomNavOpacity = useRef(new Animated.Value(1)).current;
const [optionsAlertOpen, setOptionsAlertOpen] = useState(false);
const [copiedText, setCopiedText] = useState('');
const [searchAlertOpen, setSearchAlertOpen] = useState(false);
const INJECTEDJAVASCRIPT = `
const meta = document.createElement('meta'); meta.setAttribute('content', 'initial-scale=1.0, maximum-scale=1.0'); meta.setAttribute('name', 'viewport'); document.getElementsByTagName('head')[0].appendChild(meta);
var links = document.links, i, length;
for (i = 0, length = links.length; i < length; i++) {
links[i].target == '_blank' && links[i].removeAttribute('target');
}
window.ReactNativeWebView.postMessage(document.title);
`;
const inputRef = React.useRef();
const webviewRef = useRef(null);
const [searchOpen, setSearchOpen] = useState(false);
const [searchValue, setSearchValue] = useState("");
const [bookmarksKeyValue, setBookmarksKeyValue] = useState("");
const appInfo = useSelector((state) => state.appInfo);
useEffect(() => {
Keyboard.addListener("keyboardDidShow", _keyboardDidShow);
Keyboard.addListener("keyboardDidHide", _keyboardDidHide);
// cleanup function
return () => {
Keyboard.removeListener("keyboardDidShow", _keyboardDidShow);
Keyboard.removeListener("keyboardDidHide", _keyboardDidHide);
};
}, []);
const speechToTextHandler = async () => {
let speechToTextData = null;
try {
speechToTextData = await SpeechToText.startSpeech('Try saying something', 'en_IN');
searchStringS(speechToTextData);
} catch (error) {
// error
}
}
const _keyboardDidShow = () => {
if(route.name == "Search"){
setF2(true);
} else {
// Do nothing
}
};
const _keyboardDidHide = () => {
if(route.name == "Search"){
setF2(false);
} else {
// Do nothing
}
};
const showToast = () => {
ToastAndroid.show("URL copied", ToastAndroid.SHORT);
};
useEffect(() => {
setTimeout(() => {
setWebViewShow(true);
}, 600);
}, []);
const se1 = () => {
if (webviewRef.current){
if(canGoBack) {
webviewRef.current.goBack();
} else {
navigation.goBack();
}
}
}
const se2 = () => {
if (webviewRef.current) webviewRef.current.goForward();
}
const se3 = () => {
navigation.navigate('Home', { name: "Home" });
}
const setHttpIcon = () => {
if(cUrl.substring(0, 5) == "https") {
setHttpS(1);
} else if (cUrl.substring(0, 5) == "http:") {
setHttpS(2);
} else {
setHttpS(3);
}
}
const getBookmarkValue = async () => {
try {
const value = await AsyncStorage.getItem("bookmarksKey")
if(value !== null) {
// value previously stored
setBookmarksKeyValue(value);
} else {
setBookmarksKeyValue("");
}
} catch(e) {
// error
}
}
const saveBookmarkValue = async () => {
try {
const value = await AsyncStorage.getItem("bookmarksKey")
if(value !== null) {
// value previously stored
await AsyncStorage.setItem("bookmarksKey", value + "~" + currentUrl);
setBookmarksKeyValue(value + "~" + currentUrl);
} else {
await AsyncStorage.setItem("bookmarksKey", currentUrl + "~");
setBookmarksKeyValue(currentUrl + "~");
}
} catch(e) {
// error
}
}
useEffect(() => {
navigation.addListener('focus',
() => {
let urlToOpen = (route.params.name).replace("turbo/", "");
setCurrentUrl(urlToOpen);
setWebTS(urlToOpen.split("/")[2] > 26 ? cUrl.split("/")[2].substring(0, 24) + "..." : cUrl.split("/")[2]);
setHttpS(2);
setF2(false);
getBookmarkValue();
}
);
}, []);
const refreshWeb = () => {
if (webviewRef.current) webviewRef.current.reload();
}
const onMessage = async (message) => {
setTitleCurrent(message.nativeEvent.data);
if(message.nativeEvent.data !== ""){
let objectToSet = {
name: message.nativeEvent.data,
url: message.nativeEvent.url
}
let valueToSet = JSON.stringify(objectToSet);
await AsyncStorage.setItem("lastSearchedWeb", valueToSet);
}
}
const handleFullScrTouch = () => {
if(fullscreen){
setFullscreen(false);
Animated.timing(
BottomNavOpacity,
{
toValue: 0,
duration: 0,
useNativeDriver: true,
}
).start();
setTimeout(() => {
Animated.timing(
BottomNavOpacity,
{
toValue: 1,
duration: appInfo.animations == false ? 0 : 200,
useNativeDriver: true,
}
).start();
}, 200);
} else {
setFullscreen(true);
Animated.timing(
BottomNavOpacity,
{
toValue: 0,
duration: appInfo.animations == false ? 0 : 100,
useNativeDriver: true,
}
).start();
}
}
const se4 = () => {
saveBookmarkValue();
}
const se5 = () => {
setOptionsAlertOpen(true);
}
const onShare = async () => {
try {
const result = await Share.share({
message: currentUrl,
});
if (result.action === Share.sharedAction) {
if (result.activityType) {
// shared with activity type of result.activityType
} else {
// shared
}
} else if (result.action === Share.dismissedAction) {
// dismissed
}
} catch (error) {
// error
}
};
const copyToClipboard = () => {
Clipboard.setString(currentUrl);
};
const onSearchChangeText = (text) => {
setSearchValue(text);
}
const saveHistory = async () => {
if(currentUrl !== "about:blank" || currentUrl !== "" || currentUrl.includes("~"))
try {
const value = await AsyncStorage.getItem("historyKey");
if(value !== null) {
// value previously stored
if(value.includes("~")){
await AsyncStorage.setItem("historyKey", currentUrl + "~" + value);
} else {
await AsyncStorage.setItem("historyKey", currentUrl + "~" + value);
}
} else {
await AsyncStorage.setItem("historyKey", currentUrl);
}
} catch (error) {
// error
}
}
const searchStringS = (string) => {
if(string == ""){
} else if (string.substring(0, 8) == "https://" || string.substring(0, 7) == "http://") {
setCurrentUrl(string);
} else {
// openWebsite("https://www.google.com/search?q=" + string.replace(/ /g,"+"));
if(appInfo.searchEngine == "Google"){
setCurrentUrl("https://www.google.com/search?q=" + string.replace(/ /g,"+"));
} else if (appInfo.searchEngine == "DuckDuckGo") {
openWebsite("https://duckduckgo.com/?q=" + string.replace(/ /g,"+"));
} else if (appInfo.searchEngine == "Bing") {
setCurrentUrl("https://www.bing.com/search?q=" + string.replace(/ /g,"+"));
} else if (appInfo.searchEngine == "Yahoo!") {
setCurrentUrl("https://in.search.yahoo.com/search?p=" + string.replace(/ /g,"+"));
} else {
setCurrentUrl("https://www.google.com/search?q=" + string.replace(/ /g,"+"));
}
}
}
const voiceSearchBtnClk = () => {
speechToTextHandler();
setSearchAlertOpen(false);
setSearchOpen(false);
}
const se4Remove = async () => {
try {
const value = await AsyncStorage.getItem("bookmarksKey");
const newValue = value.split(currentUrl).join("");
await AsyncStorage.setItem("bookmarksKey", newValue);
setBookmarksKeyValue(newValue);
} catch(e) {
// error
}
}
return (
<SafeAreaView>
<StatusBar backgroundColor="#ffffff" barStyle={styleStatusBar} />
<Modal
isOpen={searchAlertOpen}
onClosed={() => {
setSearchAlertOpen(false);
setSearchOpen(false);
}}
style={[styles.modal, styles.modal12]}
entry={"top"}
position={"top"}
backdropPressToClose={true}
swipeToClose={false}
backdropOpacity={0.4}
backButtonClose={true}
coverScreen={true}
animationDuration={200}
>
<View style={styles.view__2}>
<View style={{borderRadius: 40, overflow: 'hidden'}}>
{/* <TouchableOpacity
style={{width: "100%"}}
> */}
<View style={styles.view_input_c_1}>
<IonicIcon style={styles.search_icon} name="search"/>
<TextInput
ref={inputRef}
style={{
// maxWidth: 200,
fontSize: 14,
color: "#5B5D5DFF",
marginLeft: 8,
fontFamily: "Helvetica",
flexGrow: 1,
}}
value={searchValue}
onChangeText={(text) => onSearchChangeText(text)}
autoFocus={true}
editable={searchOpen}
onSubmitEditing={() => {
setSearchAlertOpen(false);
setSearchOpen(false);
searchStringS(searchValue);
}}
placeholderTextColor="#CECFCFFF"
placeholder="Search Google"
/>
{
searchValue.length > 0 ?
<IonicIcon onPress={() => setSearchValue("")} style={styles.mic_icon} name="close"/>
:
<IonicIcon onPress={voiceSearchBtnClk} style={styles.mic_icon} name="mic"/>
}
</View>
{/* </TouchableOpacity> */}
</View>
</View>
</Modal>
<Modal
isOpen={optionsAlertOpen}
onClosed={() => {setOptionsAlertOpen(false)}}
style={[styles.modal, styles.modal8]}
position={"bottom"}
backdropPressToClose={true}
swipeToClose={false}
backdropOpacity={0.2}
backButtonClose={true}
coverScreen={true}
animationDuration={200}
>
<View style={styles.optionAlertCont_MAIN}>
<View style={styles.optionAlertCont_opt_1}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
copyToClipboard();
showToast();
}}>
<Text style={styles.optionAlertCont_optText_1}>
Copy URL
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_1}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
setTimeout(() => {
onShare();
}, 320);
}}>
<Text style={styles.optionAlertCont_optText_1}>
Share
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_1}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
setCurrentUrl("view-source:" + currentUrl);
}}>
<Text style={styles.optionAlertCont_optText_1}>
View page source
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_1}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
navigation.navigate('Bookmarks', { name: "Home" });
}}>
<Text style={styles.optionAlertCont_optText_1}>
Bookmarks
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_1}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
navigation.navigate('History', { name: "Home" });
}}>
<Text style={styles.optionAlertCont_optText_1}>
History
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_1}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
navigation.navigate('Settings', { name: "Home" });
}}>
<Text style={styles.optionAlertCont_optText_1}>
Settings
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_1}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
setCurrentUrl("https://turbo-browser.netlify.app/privacy-policy.html");
}}>
<Text style={styles.optionAlertCont_optText_1}>
Privacy Policy
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_1_B}>
<TouchableOpacity onPress={() => {
setOptionsAlertOpen(false);
navigation.navigate('Help', { name: "Home" });
}}>
<Text style={styles.optionAlertCont_optText_1}>
FAQs
</Text>
</TouchableOpacity>
</View>
<View style={styles.optionAlertCont_opt_icon_1}>
<TouchableOpacity style={{
width: "100%",
display: "flex",
alignItems: "center",
justifyContent: "center",
paddingBottom: 10,
marginBottom: 4,
}} onPress={() => {setOptionsAlertOpen(false)}}>
{/* <FontAwesome style={styles.optionAlertCont_opt_icon_2} name="chevron-down"/> */}
<Image
source={require("../assets/arrowDown2.png")}
style={{
height: 26,
width: 26,
}}
/>
</TouchableOpacity>
</View>
</View>
</Modal>
<View style={styles.searchMainContainer}>
{/* Search 1 */}
<View style={styles.search_1}>
{
currentUrl.includes("view-source:") ?
<View style={styles.sea1__1}>
<Image
style={styles.sea1__1A}
source={(favIcon.includes("https://api.statvoo.com/favicon/?url=https://www.nytimes.com/") ? require("../assets/ny.png") :
favIcon.includes("https://api.statvoo.com/favicon/?url=https://www.google.com/") ? require("../assets/googleIcon.png") :
{uri: favIcon})}
/>
</View>
:
<View style={styles.sea1__1}>
{WebL ?
<ActivityIndicator size="small" style={{
height: 16,
width: 16,
resizeMode: "cover",
marginLeft: 8,
marginRight: 8,
}} color={'#8F8D8DFE'} />
:
<Image
style={styles.sea1__1A}
source={(favIcon.includes("https://api.statvoo.com/favicon/?url=https://www.nytimes.com/") ? require("../assets/ny.png") :
favIcon.includes("https://api.statvoo.com/favicon/?url=https://www.google.com/") ? require("../assets/googleIcon.png") :
{uri: favIcon})}
/>
}
</View>
}
<View style={{
height: 30,
borderRadius: 30,
flexGrow: 1,
overflow: "hidden",
}}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AEAEAEFF", rippleOverflow)}
onPress={() => {
setSearchAlertOpen(true);
setSearchValue("");
setTimeout(() => {
setSearchOpen(true);
inputRef.current?.focus();
}, 400);
}}
>
<View style={styles.sea1__2}>
<View style={styles.sea1__2A}>
{
(httpS == 1) ?
<MaterialIcons style={styles.sea1__2A_icon1} name="https"/>
: (httpS == 2) ?
<MaterialIcons style={styles.sea1__2A_icon2} name="https"/>
: (httpS == 3) ?
<MaterialIcons style={styles.sea1__2A_icon2} name="https"/>
: <MaterialIcons style={styles.sea1__2A_icon2} name="https"/>
}
</View>
<View style={styles.sea1__2B}>
<Text style={styles.sea1__2B_txt}>
{currentUrl.replace("turbo/", "").split("/")[2] > 26 ? cUrl.split("/")[2].substring(0, 24) + "..." : cUrl.split("/")[2]}
</Text>
</View>
<TouchableOpacity onPress={refreshWeb}>
<View style={styles.sea1__2C}>
<MaterialIcons style={styles.sea1__2C_icon} name="replay"/>
</View>
</TouchableOpacity>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.sea1__3}>
<TouchableOpacity onPress={handleFullScrTouch}>
{/* <MaterialIcons style={styles.sea1__3_icon} name="more-vert"/> */}
{
fullscreen ?
<MaterialIcons style={styles.sea1__3_icon} name="fullscreen-exit"/>
:
<MaterialIcons style={styles.sea1__3_icon} name="fullscreen"/>
}
</TouchableOpacity>
</View>
</View>
{/* Search 2 */}
<View style={styles.search_2}>
{
webViewShow ?
<WebView
startInLoadingState={true}
ref={webviewRef}
source={{
uri: currentUrl,
}}
onNavigationStateChange={navState => {
setCanGoBack(navState.canGoBack);
setCanGoForward(navState.canGoForward);
setCUrl(navState.url);
// setWebTS(cUrl.split("/")[2] > 26 ? cUrl.split("/")[2].substring(0, 24) + "..." : cUrl.split("/")[2]);
}}
allowFileAccess={true}
geolocationEnabled={true}
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
injectedJavaScript={INJECTEDJAVASCRIPT}
onLoadStart={() => {
setWebL(true);
}}
onLoadEnd={() => {
setFavIcon("https://api.statvoo.com/favicon/?url=" + cUrl);
setWebL(false);
setHttpIcon();
setWebTS(cUrl.split("/")[2] > 26 ? cUrl.split("/")[2].substring(0, 24) + "..." : cUrl.split("/")[2]);
saveHistory();
}}
userAgent="Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36"
onMessage={onMessage}
javaScriptEnabled={appInfo.disableJS == true ? false : true}
domStorageEnabled={appInfo.disableCookies == true ? false : true}
/>
: <></>
}
</View>
{/* Search 3 */}
{
fullscreen || f2 ?
<></>
:
<Animated.View
style={{
opacity: BottomNavOpacity
}}
>
<View style={styles.search_3}>
<TouchableOpacity onPress={se1} style={styles.sea_3_item}>
<View>
<IonicIcon style={styles.sea3__3_icon} name="chevron-back-outline"/>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={se2} style={styles.sea_3_item}>
<View>
<IonicIcon style={styles.sea3__3_icon} name="chevron-forward-outline"/>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={se3} style={styles.sea_3_item}>
<View>
<IonicIcon style={styles.sea3__3_icon} name="home-outline"/>
</View>
</TouchableOpacity>
{
bookmarksKeyValue.includes(currentUrl) ?
<TouchableOpacity onPress={se4Remove} style={styles.sea_3_item}>
<View>
<IonicIcon style={styles.sea3__3_icon_r} name="heart"/>
</View>
</TouchableOpacity>
:
<TouchableOpacity onPress={se4} style={styles.sea_3_item}>
<View>
<IonicIcon style={styles.sea3__3_icon_r} name="heart-outline"/>
</View>
</TouchableOpacity>
}
{/* <TouchableOpacity onPress={se4} style={styles.sea_3_item}>
<View>
{
bookmarksKeyValue.includes(currentUrl) ?
<IonicIcon style={styles.sea3__3_icon_r} name="heart"/>
:
<IonicIcon style={styles.sea3__3_icon} name="heart-outline"/>
}
</View>
</TouchableOpacity> */}
<TouchableOpacity onPress={se5} style={styles.sea_3_item}>
{/* Future Tab Feature */}
{/* <View style={{justifyContent: "center", alignItems: "center"}}>
<View style={{
height: 17,
width: 17,
borderWidth: 1.6,
borderRadius: 4,
borderColor: "#767778FE",
alignItems: "center",
justifyContent: "center",
}}>
<Text style={{
color: "#767778FE",
fontSize: 10,
textAlign: "center",
fontWeight: "bold",
}}>
1
</Text>
</View>
</View> */}
<View>
<IonicIcon style={styles.sea3__3_icon} name="grid-outline"/>
</View>
</TouchableOpacity>
</View>
</Animated.View>
}
</View>
</SafeAreaView>
);
}
Example #12
Source File: Settings.js From Turbo-Browser with MIT License | 4 votes |
Settings = ({ navigation, route }) => {
const styleTypes = ['default','dark-content', 'light-content'];
const [styleStatusBar, setStyleStatusBar] = useState(styleTypes[1]);
const [rippleOverflow, setRippleOverflow] = useState(false);
const [searchEngineAlert, setSearchEngineAlert] = useState(false);
const [selectedSelection, setSelectedSelection] = useState("Google");
const [defaultBrowserNum, setDefaultBrowserNum] = useState(1);
const appInfo = useSelector((state) => state.appInfo);
const dispatch = useDispatch();
const [isAnimationEnabled, setIsAnimationEnabled] = useState(true);
const [isAnimationDirEnabled, setIsAnimationDirEnabled] = useState(true);
const [isCookiesDisabled, setIsCookiesDisabled] = useState(false);
const [isJSDisabled, setIsJSDisabled] = useState(false);
useEffect(() => {
setSelectedSelection(appInfo.searchEngine);
setIsAnimationEnabled(appInfo.animations);
setIsAnimationDirEnabled(appInfo.animationDirection);
setIsCookiesDisabled(appInfo.disableCookies);
setIsJSDisabled(appInfo.disableJS);
if(appInfo.searchEngine == "Google") {
setDefaultBrowserNum(1);
} else if(appInfo.searchEngine == "DuckDuckGo") {
setDefaultBrowserNum(2);
} else if(appInfo.searchEngine == "Bing") {
setDefaultBrowserNum(3);
}
else if(appInfo.searchEngine == "Yahoo!"){
setDefaultBrowserNum(4);
} else {
setDefaultBrowserNum(1);
}
}, [appInfo]);
const data = [
{
label: "Google"
},
{
label: "DuckDuckGo"
},
{
label: "Bing"
},
{
label: "Yahoo!"
}
];
const onShare = async () => {
try {
const result = await Share.share({
message:
"Try Turbo Browser. I've been using it and it's really amazing.\n\nGet it here - https://play.google.com/store/apps/details?id=com.turbo_infinitus",
});
} catch (error) {
// error
}
}
const clearAll = async () => {
try {
await AsyncStorage.clear();
dispatch({type: "CHANGE_APPINFO", value: {
searchEngine: "Google",
animations: true,
animationDirection: true,
disableCookies: false,
disableJS: false
}});
setDefaultBrowserNum(1);
setSelectedSelection("Google");
setIsAnimationEnabled(true);
setIsAnimationDirEnabled(true);
setIsCookiesDisabled(false);
setIsJSDisabled(false);
} catch(error) {
// error
}
}
const closeSearchEngine = () => {
setSearchEngineAlert(false);
}
const saveSearchEngine = async () => {
try {
await AsyncStorage.setItem("appInfo", JSON.stringify({...appInfo, searchEngine: selectedSelection}));
dispatch({type: "CHANGE_APPINFO", value: {...appInfo, searchEngine: selectedSelection}});
setSelectedSelection(selectedSelection);
closeSearchEngine();
} catch (error) {
// error
}
}
return (
<SafeAreaView>
<StatusBar backgroundColor="#ffffff" barStyle={styleStatusBar}/>
<Modal
isOpen={searchEngineAlert}
onClosed={saveSearchEngine}
style={[styles.modal, styles.modal4]}
position={"center"}
backdropPressToClose={true}
swipeToClose={false}
backdropOpacity={0.2}
backButtonClose={true}
coverScreen={true}
animationDuration={200}
>
<View style={styles.modal4__1A}>
<View style={{
display: "flex",
flexDirection: "row",
marginTop: 20,
marginBottom: 5,
}}>
<Text style={{
fontSize: 16,
color: "#6C7377FE",
fontFamily: "Helvetica",
marginLeft: 20,
marginTop: 4,
marginRight: 10,
paddingBottom: 4,
flexGrow: 1,
}}>
Search Engine
</Text>
<TouchableOpacity onPress={closeSearchEngine}>
<View>
<IonicIcon name="chevron-down" style={{
fontSize: 20,
color: "#6C7377FE",
marginRight: 20,
marginTop: 4,
}}/>
</View>
</TouchableOpacity>
</View>
<View>
<View style={{
marginLeft: 10,
marginBottom: 30,
}}>
<RadioButtonRN
data={data}
box={false}
initial={defaultBrowserNum}
selectedBtn={(e) => {setSelectedSelection(e.label)}}
animationTypes={[]}
textColor="#6C7377FE"
circleSize={14}
duration={200}
textStyle={{
fontFamily: "Helvetica",
marginTop: 2,
marginBottom: 2,
fontSize: 15,
}}
icon={
<IonicIcon name="checkmark-circle-outline" style={{
fontSize: 22,
color: "#6C7377FE",
}}/>
}
/>
</View>
</View>
</View>
</Modal>
<View style={styles.history_title_1}>
<TouchableOpacity onPress={() => {navigation.goBack()}}>
<View style={styles.history1_AA}>
<IonicIcon name="arrow-back" style={styles.history_title_1A_icon}/>
</View>
</TouchableOpacity>
<View style={styles.history1_BB}>
<Text style={styles.history_title_1B_txt}>Settings</Text>
</View>
</View>
{/* <LinearGradient colors={['#EDEEEEFE', '#FFFFFFFF']} style={styles.linearGradient_1}></LinearGradient> */}
<ScrollView style={styles.settingsMainContainer} showsVerticalScrollIndicator={false} keyboardShouldPersistTaps={'handled'} scrollEventThrottle={1}>
<View>
<Text style={styles.section_1_txt}>BASICS</Text>
</View>
<View style={styles.section_1_CONT_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AFB1B13D", rippleOverflow)}
onPress={() => {setSearchEngineAlert(true)}}
>
<View>
<Text style={styles.section_1_txt_A}>
Search Engine
</Text>
<Text style={styles.section_1_txt_B}>
{selectedSelection}
</Text>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#FFFFFF", rippleOverflow)}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Enable Animations
</Text>
<Switch
trackColor={{ false: "#EAE7E7FE", true: "#9DFEBEFE" }}
thumbColor={isAnimationEnabled ? "#3AE07AFE" : "#CCCED0FE"}
value={isAnimationEnabled}
onValueChange={async () => {
try {
await AsyncStorage.setItem("appInfo", JSON.stringify({...appInfo, animations: !isAnimationEnabled}));
dispatch({type: "CHANGE_APPINFO", value: {...appInfo, animations: !isAnimationEnabled}});
setIsAnimationEnabled(!isAnimationEnabled);
} catch(error) {
// error
}
}}
/>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#FFFFFF", rippleOverflow)}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Toggle Animation Direction
</Text>
<Switch
trackColor={{ false: "#EAE7E7FE", true: "#9DFEBEFE" }}
thumbColor={isAnimationDirEnabled ? "#3AE07AFE" : "#CCCED0FE"}
value={isAnimationDirEnabled}
onValueChange={async () => {
try {
await AsyncStorage.setItem("appInfo", JSON.stringify({...appInfo, animationDirection: !isAnimationDirEnabled}));
dispatch({type: "CHANGE_APPINFO", value: {...appInfo, animationDirection: !isAnimationDirEnabled}});
setIsAnimationDirEnabled(!isAnimationDirEnabled);
} catch(error) {
// error
}
}}
/>
</View>
</TouchableNativeFeedback>
</View>
<View style={{
minHeight: 1,
backgroundColor: "#EDEEEEFE",
marginTop: 10,
marginBottom: 10,
}}></View>
<View>
<Text style={styles.section_1_txt}>ADVANCED</Text>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AFB1B13D", rippleOverflow)}
onPress={() => {
// -- x
CookieManager.clearAll()
.then((res) => {
Snackbar.show({
text: "Cookies cleared successfully",
duration: Snackbar.LENGTH_SHORT,
backgroundColor: "#282C34FF",
});
});
}}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Clear Cookies
</Text>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AFB1B13D", rippleOverflow)}
onPress={ () =>
{
// ;-;
Snackbar.show({
text: "Cache cleared successfully",
duration: Snackbar.LENGTH_SHORT,
backgroundColor: "#282C34FF",
});
}
}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Clear Cache
</Text>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AFB1B13D", rippleOverflow)}
onPress={() => {
clearAll();
Snackbar.show({
text: "App Data was cleared successfully",
duration: Snackbar.LENGTH_SHORT,
backgroundColor: "#282C34FF",
});
}}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Clear App Data
</Text>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#FFFFFF", rippleOverflow)}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Disable Cookies
</Text>
<Switch
trackColor={{ false: "#EAE7E7FE", true: "#9DFEBEFE" }}
thumbColor={isCookiesDisabled ? "#3AE07AFE" : "#CCCED0FE"}
value={isCookiesDisabled}
onValueChange={async () => {
try {
await AsyncStorage.setItem("appInfo", JSON.stringify({...appInfo, disableCookies: !isCookiesDisabled}));
dispatch({type: "CHANGE_APPINFO", value: {...appInfo, disableCookies: !isCookiesDisabled}});
setIsCookiesDisabled(!isCookiesDisabled);
} catch(error) {
// error
}
}}
/>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#FFFFFF", rippleOverflow)}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Disable Javascript
</Text>
<Switch
trackColor={{ false: "#EAE7E7FE", true: "#9DFEBEFE" }}
thumbColor={isJSDisabled ? "#3AE07AFE" : "#CCCED0FE"}
value={isJSDisabled}
onValueChange={async () => {
try {
await AsyncStorage.setItem("appInfo", JSON.stringify({...appInfo, disableJS: !isJSDisabled}));
dispatch({type: "CHANGE_APPINFO", value: {...appInfo, disableJS: !isJSDisabled}});
setIsJSDisabled(!isJSDisabled);
} catch(error) {
// error
}
}}
/>
</View>
</TouchableNativeFeedback>
</View>
<View style={{
minHeight: 1,
backgroundColor: "#EDEEEEFE",
marginTop: 10,
marginBottom: 10,
}}></View>
<View>
<Text style={styles.section_1_txt}>APP</Text>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AFB1B13D", rippleOverflow)}
onPress={() => {
navigation.navigate('Search', { name: "turbo/https://turbo-browser-policy.netlify.app/" });
}}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Privacy Policy
</Text>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AFB1B13D", rippleOverflow)}
onPress={() => {
navigation.navigate('Search', { name: "turbo/https://turbo-browser.netlify.app/" });
}}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Visit Website
</Text>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AFB1B13D", rippleOverflow)}
onPress={() => {
navigation.navigate('Help', { name: "Home" });
}}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
FAQs
</Text>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AFB1B13D", rippleOverflow)}
onPress={onShare}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Share App
</Text>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AFB1B13D", rippleOverflow)}
onPress={() => {
Linking.openURL("https://play.google.com/store/apps/details?id=com.turbo_infinitus");
}}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Rate App
</Text>
</View>
</TouchableNativeFeedback>
</View>
<View style={{
minHeight: 1,
backgroundColor: "#EDEEEEFE",
marginTop: 10,
marginBottom: 10,
}}></View>
<View>
<Text style={styles.section_1_txt}>ABOUT</Text>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AFB1B13D", rippleOverflow)}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Version
</Text>
<Text style={styles.section_1_txt_A_TF2_BOLD}>
5.4.3
</Text>
</View>
</TouchableNativeFeedback>
</View>
<View style={styles.section_1_CONT_SWH_1}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple("#AFB1B13D", rippleOverflow)}
>
<View style={{
display: "flex",
flexDirection: "row",
marginLeft: 12,
marginRight: 12,
}}>
<Text style={styles.section_1_txt_A_TF2}>
Version code
</Text>
<Text style={styles.section_1_txt_A_TF2_BOLD}>
54
</Text>
</View>
</TouchableNativeFeedback>
</View>
<View style={{
minHeight: 80,
}}></View>
</ScrollView>
</SafeAreaView>
);
}
Example #13
Source File: DrillPage.test.js From UltimateApp with MIT License | 4 votes |
describe('<DrillPage />', () => {
afterEach(() => jest.clearAllMocks());
const drill = store.getState().drills[0];
const toggleFavorite = jest.fn();
it('renders correctly', async () => {
const Stack = createStackNavigator();
const { toJSON } = render(
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="DrillPage" component={ConnectedDrillPage} initialParams={{ id: drill.id }} />
</Stack.Navigator>
</NavigationContainer>
</Provider>,
);
await waitFor(async () => expect(toJSON()).toMatchSnapshot());
});
it('renders correctly a favorite drill', async () => {
const MockedConnectedDrillPage = connect(
() => ({ favoriteDrills: [drill.id], drills: [drill] }),
() => ({ toggleFavorite }),
)(DrillPage);
const Stack = createStackNavigator();
const { toJSON } = render(
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="DrillPage" component={MockedConnectedDrillPage} initialParams={{ id: drill.id }} />
</Stack.Navigator>
</NavigationContainer>
</Provider>,
);
await waitFor(async () => expect(toJSON()).toMatchSnapshot());
});
it('toggles favorite drill', async () => {
const MockedConnectedDrillPage = connect(
() => ({ favoriteDrills: [], drills: store.getState().drills }),
() => ({ toggleFavorite }),
)(DrillPage);
const Stack = createStackNavigator();
const { getByTestId } = render(
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="DrillPage" component={MockedConnectedDrillPage} initialParams={{ id: drill.id }} />
</Stack.Navigator>
</NavigationContainer>
</Provider>,
);
fireEvent.press(getByTestId('favoriteButton'));
await waitFor(() => expect(toggleFavorite).toBeCalledWith(drill));
});
it('triggers share', async () => {
jest.spyOn(firebase, 'createLink').mockImplementation(() => '');
const share = jest.fn();
Share.share = () => new Promise((resolve, reject) => share());
const Stack = createStackNavigator();
const { getByTestId } = await waitFor(() =>
render(
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="DrillPage" component={ConnectedDrillPage} initialParams={{ id: drill.id }} />
</Stack.Navigator>
</NavigationContainer>
</Provider>,
),
);
fireEvent.press(getByTestId('shareButton'));
await expect(firebase.createLink).toHaveBeenCalled();
expect(share).toHaveBeenCalled();
});
it('links to fitness page for fitness', async () => {
const navigate = jest.fn();
const Stack = createStackNavigator();
const { getByTestId } = await waitFor(() =>
render(
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="DrillPage"
component={ConnectedDrillPage}
initialParams={{ id: drill.id }}
listeners={({ navigation }) => ({
transitionStart: (e) => {
navigation.navigate = navigate;
},
})}
/>
</Stack.Navigator>
</NavigationContainer>
</Provider>,
),
);
fireEvent.press(getByTestId('startButton'));
expect(navigate).toBeCalledWith('FitnessPage', { drill });
});
});
Example #14
Source File: RecordItem.js From react-native-nfc-rewriter with MIT License | 4 votes |
function RecordItem(props) {
const {record, removeIdx, goToHandler, onCopy, idx} = props;
return (
<List.Item
title={record.name}
right={() => (
<View
style={{
flexDirection: 'row',
alignItems: 'center',
alignSelf: 'center',
}}>
<IconButton
icon={() => (
<Icon name="delete" size={22} style={{alignSelf: 'center'}} />
)}
onPress={() => removeIdx(idx)}
/>
<IconButton
icon={() => (
<Image
source={require('../../../images/save_as.png')}
style={{width: 24, height: 24}}
resizeMode="contain"
/>
)}
onPress={() => onCopy()}
/>
<IconButton
icon={() => (
<Icon name="share" size={22} style={{alignSelf: 'center'}} />
)}
onPress={() => {
Share.share({
title: 'My NFC Record',
url: `com.revteltech.nfcopenrewriter://share?data=${JSON.stringify(
record,
)}`,
});
}}
/>
<IconButton
icon={() => (
<Icon
name="arrow-forward"
size={22}
style={{alignSelf: 'center'}}
/>
)}
onPress={() => goToHandler(record)}
/>
</View>
)}
/>
);
}
Example #15
Source File: HomeScreen.js From stayaway-app with European Union Public License 1.2 | 4 votes |
export default function HomeScreen () {
const dispatch = useDispatch();
const tracingEnabled = useSelector(isTracingEnabled);
const infectionStatus = useSelector(getInfectionStatus);
const hasBluetoothError = useSelector(hasBluetoothDisabledError);
const hasLocationError = useSelector(hasLocationDisabledError);
const hasBatteryError = useSelector(hasBatteryOptimizerError);
const hasExposureNotificationsError = useSelector(hasExposureNotificationsDisabledError);
let error = {
status: false,
title: '',
message: '',
accessibility: {
label: '',
hint: '',
},
icon: undefined,
onPress: () => {},
};
if (infectionStatus !== INFECTION_STATUS.INFECTED) {
if (hasExposureNotificationsError) {
error = {
status: true,
title: i18n.translate(`screens.home.errors.gaen.${Platform.OS}.title`),
message: i18n.translate(`screens.home.errors.gaen.${Platform.OS}.message`),
icon: <Icon name='gaen_disconnected' width={iconSizes.size32} height={iconSizes.size32} />,
main: {
label: i18n.translate(`screens.home.errors.gaen.${Platform.OS}.label`),
accessibility: {
label: i18n.translate(`screens.home.errors.gaen.${Platform.OS}.accessibility.label`),
hint: i18n.translate(`screens.home.errors.gaen.${Platform.OS}.accessibility.hint`),
},
onPress: () => dispatch(accountActions.enableExposureNotifications()),
},
};
} else if (! tracingEnabled) {
error = {
status: true,
title: i18n.translate('screens.home.errors.tracing.title'),
message: i18n.translate('screens.home.errors.tracing.message'),
icon: <Icon name='gaen_disconnected' width={iconSizes.size32} height={iconSizes.size32} />,
main: {
label: i18n.translate('screens.home.errors.tracing.label'),
accessibility: {
label: i18n.translate('screens.home.errors.tracing.accessibility.label'),
hint: i18n.translate('screens.home.errors.tracing.accessibility.hint'),
},
onPress: () => dispatch(accountActions.startTracing()),
},
};
} else if (hasBluetoothError) {
error = {
status: true,
title: i18n.translate(`screens.home.errors.bluetooth.${Platform.OS}.title`),
message: i18n.translate(`screens.home.errors.bluetooth.${Platform.OS}.message`),
icon: <Icon name='bluetooth_disconnected' width={iconSizes.size17} height={iconSizes.size28} />,
main: {
label: i18n.translate(`screens.home.errors.bluetooth.${Platform.OS}.label`),
accessibility: {
label: i18n.translate(`screens.home.errors.${Platform.OS}.bluetooth.accessibility.label`),
hint: i18n.translate(`screens.home.errors.${Platform.OS}.bluetooth.accessibility.hint`),
},
onPress: Platform.select({
android: () => TracingManager.requestBluetoothService(),
ios: () => Linking.openURL('App-prefs:root=Bluetooth'),
}),
},
};
} else if (hasLocationError) {
error = {
status: true,
title: i18n.translate('screens.home.errors.location.title'),
message: i18n.translate('screens.home.errors.location.message'),
icon: <Icon name='location_disconnected' width={iconSizes.size23} height={iconSizes.size26} />,
main: {
label: i18n.translate('screens.home.errors.location.label'),
accessibility: {
label: i18n.translate('screens.home.errors.location.accessibility.label'),
hint: i18n.translate('screens.home.errors.location.accessibility.hint'),
},
onPress: () => RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({}),
},
};
} else if (hasBatteryError) {
error = {
status: true,
title: i18n.translate('screens.home.errors.battery.title'),
message: i18n.translate('screens.home.errors.battery.message'),
submessage: i18n.translate('screens.home.errors.battery.submessage'),
icon: <Icon name='battery_optimized' width={iconSizes.size14} height={iconSizes.size28} />,
main: {
label: i18n.translate('screens.home.errors.battery.actions.main.label'),
accessibility: {
label: i18n.translate('screens.home.errors.battery.actions.main.accessibility.label'),
hint: i18n.translate('screens.home.errors.battery.actions.main.accessibility.hint'),
},
onPress: () => dispatch(accountActions.requestIgnoreBatteryOptimizations()),
},
alternative: {
label: i18n.translate('screens.home.errors.battery.actions.alternative.label'),
accessibility: {
label: i18n.translate('screens.home.errors.battery.actions.alternative.accessibility.label'),
hint: i18n.translate('screens.home.errors.battery.actions.alternative.accessibility.hint'),
},
onPress: () => Linking.openURL(i18n.translate('common.links.faqs')),
},
};
}
}
const onLongPressSettings = () => {
if (Configuration.UI) {
dispatch(
accountActions.setInfectionStatus(infectionStatus === 2 ? 0 : infectionStatus + 1),
);
}
};
const props = {
infectionStatus,
lastSync: useSelector(getLastSync),
error,
onPressSettings: () => NavigationService.navigate(AppRoutes.SETTINGS),
onPressShare: () => Share.share({
title: i18n.translate('common.dialogs.share.subject'),
message: i18n.translate('common.dialogs.share.message', { app_store: i18n.translate('common.links.stores.app_store'), play_store: i18n.translate('common.links.stores.play_store')}),
}, {
dialogTitle: i18n.translate('common.dialogs.share.subject'),
subject: i18n.translate('common.dialogs.share.subject'),
}),
onLongPressSettings,
};
return (
<Home {...props} />
);
}
Example #16
Source File: index.js From tcap-mobile with GNU General Public License v3.0 | 4 votes |
Details = () =>{
const walletService = WalletService.getInstance();
const pk = walletService.pk;
const accAddress = walletUtils.createAddressFromPrivateKey(pk);
const [isActive, setIsActive] = useState(false);
const [qrSvg , setQrSvg] = useState(undefined);
useEffect(()=>{generateQR();},[]);
const generateQR = async() => {
let svg = await QRCode.toString(accAddress,{type:'terminal'});
setQrSvg(svg);
};
const copyToClipboard = () =>{
Clipboard.setString(accAddress);
Toast.show('Address Copied to Clipboard',Toast.LONG);
};
const shareAddress = () =>{
Share.share({
message: accAddress,
}, {
// Android only:
dialogTitle: 'Trustless Capital - Account Address',
// iOS only:
excludedActivityTypes: [
'com.apple.UIKit.activity.PostToTwitter'
]
});
};
const renderQrCodeBox = () =>{
return(
<View style={styles.bottomModal}>
<TouchableOpacity onPress={()=>setIsActive(false)} style={{alignSelf:'flex-end',paddingHorizontal:moderateScale(8),padding:moderateScale(2)}}>
<Text style={{color:Colors.darkGrey}}>Done</Text>
</TouchableOpacity>
<Text style={{alignSelf:'center',fontSize:moderateScale(16),marginVertical:moderateScale(5),fontWeight:'bold'}}>Send To Your Wallet</Text>
<View style={styles.barcodeBox}>
{(!qrSvg) && <Text>Preparing...</Text>}
{
(qrSvg) &&
<WebView source={{ html: qrSvg }} style={{width:moderateScale(250),height:250,}} />
}
</View>
<TouchableOpacity onPress={()=>copyToClipboard()}>
<Text style={{...styles.accAddressText,color:Colors.darkGrey,alignSelf:'center',marginTop:moderateScale(10)}}>Account Addess</Text>
<Text style={{...styles.titleBar_title,maxWidth:moderateScale(200),color:Colors.darkGrey,alignSelf:'center',textAlign:'center'}}>{accAddress}</Text>
</TouchableOpacity>
<TouchableOpacity onPressOut={()=>shareAddress()} style={styles.shareButton}>
<Text style={{color:Colors.white}}>Share</Text>
</TouchableOpacity>
</View>
);
};
return(
<View style={{...styles.boxWrapper,justifyContent:'center',alignItems:'center'}}>
<Text style={styles.accAddressText}>Account Addess</Text>
<Text ellipsizeMode={'middle'} numberOfLines={1} style={{...styles.titleBar_title,maxWidth:moderateScale(100)}}>{accAddress}</Text>
<View style={styles.buttonWrappers}>
<TouchableOpacity onPress={()=>copyToClipboard()} style={styles.buttons}>
<Icon name={'copy'} size={moderateScale(16)} />
<Text style={styles.buttonText}>Copy</Text>
</TouchableOpacity>
<TouchableOpacity onPress={()=>setIsActive(true)} style={styles.buttons}>
<Icon name={'qrcode'} size={moderateScale(16)} />
<Text style={styles.buttonText}>Receive</Text>
</TouchableOpacity>
</View>
<Modal
animationIn={'slideInUp'}
animationOut={'slideOutDown'}
backdropColor={'#000'}
dismissable={true}
isVisible={isActive}
onBackButtonPress={()=>setIsActive(false)}
onBackdropPress={()=>setIsActive(false)}
style={{padding:0,margin:0}}
useNativeDriver={true}
>
{renderQrCodeBox()}
</Modal>
</View>
);
}