我有一个与Django频道进行通讯的React Native应用(android)。通过连接到我的开发服务器时ws,一切正常。但是,当我尝试wss使用相同的代码连接到远程服务器时,没有任何反应。
套接字连接显示为OPEN。我什至收到"connected"从服务器发送到我的应用程序的第一条消息:
class RGConsumer(AsyncWebsocketConsumer):
rooms = []
async def connect(self):
self.rooms = []
await self.join_room('all')
await self.accept()
await self.send(text_data=json.dumps({'event': 'connected'}))
async def join_room(self, room_name):
if room_name not in self.rooms:
self.rooms.append(room_name)
await self.channel_layer.group_add(
room_name,
self.channel_name
)
Run Code Online (Sandbox Code Playgroud)
问题在于,除了第一个消息之外,没有其他消息通过。例如,无论我通过此函数发送的内容如何,都不会被应用程序接收:
def send_to_all(event, data=None):
message = {'type': 'channel_event', 'message': {'event': event, 'data': data}}
channel_layer = get_channel_layer()
async_to_sync(channel_layer.group_send)(
'all',
message
)
Run Code Online (Sandbox Code Playgroud)
以相同的方式,当我调用websocket.send我的应用程序时,receive根本不会触发我的使用者的功能。
再一次,这在我的本地服务器上工作得很好,所以我认为代码是正确的。只有将应用程序连接到生产wss服务器时,它才会停止工作(除了connected收到第一条消息外)
此外,websocket.onclose如果我决定重新启动生产服务器,则该函数也不会被调用。
是否有其他设置可以允许我正确丢失与wss服务器的正确连接?
让我知道是否需要更多代码。我不确定还需要什么。
我想在用户点击按钮时显示一个模式,而不是关闭键盘。不幸的是,一旦模态出现,键盘就会消失。
最小再现案例:
import * as React from "react";
import { Button, Modal, Text, TextInput, View } from "react-native";
function TestComp() {
const [showingModal, setshowingModal] = React.useState(false);
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center", marginTop: 22 }}>
<Modal visible={showingModal} transparent onRequestClose={() => setshowingModal(false)}>
<View style={{ flex: 1, marginTop: 22 }}>
<Button title={"hide modal"} onPress={() => setshowingModal(false)} />
</View>
</Modal>
<TextInput placeholder="Focus to show keyboard" />
<Button title={"Show modal"} onPress={() => setshowingModal(true)} />
</View>
);
}
Run Code Online (Sandbox Code Playgroud)
仅供参考,我正在使用世博会。
如何强制键盘持久化?
我正在使用 React-boostrap 的 Popover 和 OverlayTrigger 类。我的问题是,当我在显示时更改弹出窗口上的内容时,它会正确调整大小,但位置会出错。即使弹出窗口不再与 OverlayTrigger 对齐,它也会保持其左上角位置
这就是我要说的:
这是我在渲染函数中使用的代码,非常简单:
const popover = (
<Popover id={this.props.htKey} >
{this.state.content}
</Popover>
);
return (
<OverlayTrigger
trigger={["hover", "focus"]}
delayShow={200}
placement="top"
overlay={popover}
onEntered={this.startExtendTimer}
onExited={this.resetContent}
>
<span>test</span>
</OverlayTrigger>
);
Run Code Online (Sandbox Code Playgroud)
调用startExtenTimer的超时会this.state.content在几秒钟后发生变化(因此导致我在图片中显示的问题)
如何在保持正确对齐的同时更改弹出窗口的内容?
我在React-native上遇到了一个问题.我有TextInput整个屏幕.我想在用户向上或向下滑动时更改此文本输入的内容.为此,我正在使用PanResponder.
问题是PanResponder窃取了焦点TextInput:当我点击时TextInput,键盘没有出现,我无法改变它的值.
有没有一种方法可以同时使用PanResponder和Textinput共存,以便点击将重点关注TextInput并且轻扫仍然会触发PanResponder回调?
我将代码减少到重现问题所需的最小值:
export default class EditNoteScreen extends Component {
componentWillMount() {
this.panResponder = PanResponder.create({
onStartShouldSetPanResponder: () => true,
onStartShouldSetPanResponderCapture: () => true,
onMoveShouldSetResponderCapture: () => true,
onMoveShouldSetPanResponderCapture: () => true
});
}
render() {
return (
<View style={stylesNote.editScreen} {...this.panResponder.panHandlers}>
<View style={stylesNote.editScreenContent}>
<TextInput style={stylesNote.editScreenInput}>
Hello
</TextInput>
</View>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
样式:
editScreen: {
flex: 1
},
editScreenContent: {
flex: 5 …Run Code Online (Sandbox Code Playgroud) 我有一个堆栈导航器,其中一个屏幕使用自定义标题:
import { createStackNavigator } from "@react-navigation/stack";
import * as React from "react";
import { Button, View } from "react-native";
const Stack = createStackNavigator();
function ScreenA({ navigation }) {
return (
<View style={{ flex: 1, justifyContent: "center"}}>
<Button title="Click me" onPress={() => navigation.navigate("ScreenB")} />
</View>
);
}
function ScreenB({ navigation }) {
return (
<View style={{ flex: 1 , justifyContent: "center"}}>
<Button title="Click me" onPress={() => navigation.navigate("ScreenA")} />
</View>
);
}
function TestComp() {
return (
<Stack.Navigator>
<Stack.Screen
name="ScreenA"
component={ScreenA} …Run Code Online (Sandbox Code Playgroud) 我刚刚从 React 导航 5 升级到 6,并查看了透明模式的文档。不幸的是,我无法在模式下显示上一个屏幕。相反,我得到的是灰色背景。
我用我的代码做了一份小吃来展示我的结果:https ://snack.expo.dev/@divone/transparent-modal-not-working
我究竟做错了什么?我似乎已经拥有文档中列出的所有元素,使其可以正常工作。
我正在使用 expo SDK 43 的托管工作流程。
Flatlist 允许您定义一个ItemSeparatorComponent接收作为默认道具highlighted和leadingItem. 前导项表示显示在分隔符之前的项。
问题是我inverted在我的 Flatlist 上使用,我的分隔符现在需要适应下一个项目而不是前一个项目。
有没有办法访问分隔符后显示的项目?像一个 trailingItem 之类的东西?
我正在使用 React 和 AWS Amplify 实现一个网页。
我的文件中有以下定义schema.graphql:
type Calendar @model {
id: ID!
name: String
description: String
url: String!
intervals: [Interval] @connection(keyName: "byCalendar", fields: ["id"])
}
Run Code Online (Sandbox Code Playgroud)
我想从 URL 字符串中获取日历。不幸的是,以下代码会引发错误:
import { API, graphqlOperation } from "aws-amplify";
import * as queries from "../../graphql/queries";
await API.graphql(graphqlOperation(queries.getCalendar, { url: "some-url"}));
Run Code Online (Sandbox Code Playgroud)
Variable "$id" of required type "ID!" was not provided.
从错误来看,提供 id 是强制性的。但是,我希望能够仅从 url 获取一个对象。
我怎样才能做到这一点?
我正在使用由 amplify 的 cli 自动生成的查询。
/* eslint-disable */
// this is an auto generated file. This …Run Code Online (Sandbox Code Playgroud) 我正在尝试建立PWA。我设法触发了第一次提示,并将应用程序安装在我的外壳(桌面)上。然后,我将其删除,我想强制再次出现提示(出于调试目的),但不会。
我将chome标志设置Bypass user engagement checks为enabled,但是仍然无法执行任何操作来触发提示。
当我单击控制台设置时Application>Manifest>Add to homescreen,什么也没有发生,并且我也没有收到任何错误消息。
它与第一次使用的代码完全相同。由于桌面快捷方式已删除,我只想再次触发它。
我有一个 ReactNative 应用程序,我试图从我的中间件列表中删除中间件“serializedStateInvariant”。页面https://redux-toolkit.js.org/api/getDefaultMiddleware缺少一些信息。
他们表示要配置商店:
const store = configureStore({
reducer: rootReducer,
middleware: [thunk, immutableStateInvariant]
})
Run Code Online (Sandbox Code Playgroud)
但没有说明如何导入thunk,或者immutableStateInvariant。
如何导入它们,以便我可以将我的中间件设置为[thunk, immutableStateInvariant], without serializableStateInvariant?
react-native ×5
expo ×2
reactjs ×2
aws-amplify ×1
django ×1
graphql ×1
manifest ×1
react-redux ×1
websocket ×1