我目前正在构建一个 React Native 应用程序,它使用 Web 套接字来提供一些实时功能。我已经实现并运行了 redux,我现在正在尝试创建将维护 Web 套接字连接的中间件。虽然我熟悉 React Native 和 Redux,但 Socket 连接对我来说是新的。应用程序连接到的服务器是用 Spring 构建的 - 它使用 SockJS 并使用 STOMP 协议。
我不确定使用 STOMP 实现中间件的正确方法。虽然我遇到了许多启动 Socket.io 连接和 SockJ 的例子,但我一直无法找到任何使用 STOMP 的例子。我正在寻找可以帮助我的示例或库。
在研究时,我遇到了,并尝试使用以下示例来启动和运行:
import SockJS from 'sockjs-client'
import Stomp from 'stomp'
var stompClient = null;
const ws_url = 'MYURL'
const token = 'MYTOKEN'
export const setupSocket = (dispatch) => {
var socket = new SockJS(ws_url+token);
stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('MY …Run Code Online (Sandbox Code Playgroud) 我是 lottie-react-native 的新手,并设法实现了我的第一个动画:
constructor(props) {
super(props);
this.state = {
progress: new Animated.Value(0),
loop: true
}
}
componentDidMount() {
this.animation.play();
}
render() {
const { progress, loop } = this.state;
return (
<View style={{display:'flex',height:'auto', alignItems: 'center',justifyContent:'center'}}>
<LottieView
ref={animation => {
this.animation = animation;
}}
speed={1}
autoPlay
source={NOACTIVITY}
progress={progress}
loop={loop}
height={300}
width={300}
style={{margin:0,}}
/>
</View>
)
Run Code Online (Sandbox Code Playgroud)
}
我现在正在尝试使用此动画创建一个循环,向前播放,然后向后播放,然后再次开始该过程。
我做了一些研究并得出结论,这必须使用动画值和时间来完成?我发现了许多向前和向后播放但不一起播放的示例(在 react native docs 中!)。
这可以在组件安装时完成吗?或者它必须是一个单独的功能?
提前致谢!
loops ×1
lottie ×1
middleware ×1
native ×1
react-native ×1
reactjs ×1
redux ×1
stomp ×1
websocket ×1