Last active
May 7, 2019 02:42
-
-
Save yehudamakarov/4837d8a954ca30610fc95ff322c7cc1e to your computer and use it in GitHub Desktop.
[React Recipes]
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
import React from 'react'; | |
import { TouchableWithoutFeedback } from 'react-native'; | |
export default class DoubleTap extends React.Component { | |
static defaultProps = { | |
delay: 300, | |
onDoubleTap: () => null, | |
}; | |
lastTap = null; | |
// https://gist.github.com/brunotavares/3c9a373ba5cd1b4ff28b | |
handleDoubleTap = () => { | |
const now = Date.now(); | |
if (this.lastTap && (now - this.lastTap) < this.props.delay) { | |
this.props.onDoubleTap(); | |
} else { | |
this.lastTap = now; | |
} | |
} | |
render() { | |
return ( | |
<TouchableWithoutFeedback onPress={this.handleDoubleTap}> | |
{this.props.children} | |
</TouchableWithoutFeedback> | |
); | |
} | |
} |
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
export default class App extends React.Component { | |
lastTap = null; | |
handleDoubleTap = () => { | |
const now = Date.now(); | |
const DOUBLE_PRESS_DELAY = 300; | |
if (this.lastTap && (now - this.lastTap) < DOUBLE_PRESS_DELAY) { | |
this.toggleLike(); | |
} else { | |
this.lastTap = now; | |
} | |
} | |
render() { | |
return ( | |
<TouchableWithoutFeedback onPress={this.handleDoubleTap}> | |
<Image | |
source={{ uri: 'https://images.pexels.com/photos/671557/pexels-photo-671557.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=${w.width}' }} | |
style={{ width: w.width, height: w.width }} | |
resizeMode="cover" | |
/> | |
</TouchableWithoutFeedback> | |
); | |
} | |
} |
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
import React from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
import * as signalR from '@aspnet/signalr'; | |
class App extends React.Component { | |
connection: signalR.HubConnection; | |
/** | |
* | |
*/ | |
constructor(props: any) { | |
super(props); | |
this.connection = new signalR.HubConnectionBuilder() | |
.withUrl("https://localhost:5001/hubs/repoSyncJobUpdates") | |
.configureLogging(signalR.LogLevel.Information) | |
.build(); | |
this.connection.start().then(() => { | |
console.log("connected") | |
}).catch((reason) => { | |
console.log(reason); | |
}) | |
this.connection.on("PushUpdate", (itemStatus: {}, jobStatus: string) => { | |
console.log(itemStatus, jobStatus); | |
}) | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<p> | |
Edit <code>src/App.tsx</code> and save to reload. | |
</p> | |
<a | |
className="App-link" | |
href="https://reactjs.org" | |
target="_blank" | |
rel="noopener noreferrer" | |
> | |
Learn React | |
</a> | |
</header> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment