我是React的新手,所以我希望我能正确解决这个问题。首先,我有一个名为SearchLocationsScreen的屏幕。在该屏幕内,我有一个名为Map的组件,在Map内有一个名为LocationMarker的自定义标记组件。在与Map组件相同的层次结构级别上,我有一个自定义的ModalBox,称为CheckinModal。这是一个粗略的图表可以帮助您:
在SearchLocationsScreen中,我从API调用中获取位置信息。然后,将这些位置传递到我的地图组件。在我的Map组件内部,我将标记的信息向下传递到自定义LocationMarker类,并填充地图。
目的是按下一个标记,并从底部弹出CheckinModal,并使用所按下的特定标记的信息填充它。为此,我使用useRef钩子和forwardRef钩子将对模式的引用传递给LocationMarker类。我在这里打电话ref.current.open(),模态按预期方式打开。
问题是我无法找到一种方法来从标记传递位置信息,将层次结构备份到屏幕上,再向下到模态以用相关信息填充模态。有谁知道如何实现这一目标?我将下面的代码发布到屏幕,地图组件和标记组件(不包括样式)。在此先感谢您的帮助。
SearchLocationsScreen.js
const SearchLocationsScreen = ({isFocused, navigation}) => {
const {updateLocation} = useContext(CurrentLocationContext);
// hooks
const callback = useCallback((location) => {
updateLocation(location)
}, []);
const [err] = useCurrentLocation(isFocused, callback);
const [businessLocations] = useGetLocations();
const modalRef = useRef(null);
let locations = [];
if (businessLocations) {
for (let x …Run Code Online (Sandbox Code Playgroud) 关于 Retrofit2 的问题:
构建 Retrofit 实例后,然后调用接口(客户端)方法之一来“发送请求”
例如,如果您有这样的界面:
@POST("webhook.php")
Call<String> queueCustomer(@Body String queue);
Run Code Online (Sandbox Code Playgroud)
以及使用 create 方法创建的“client”的 Retrofit 实例,然后像这样调用它:
client.queueCustomer(someString)
Run Code Online (Sandbox Code Playgroud)
我假设这实际上是在发出网络请求。但是,您获取从此返回的 Call 对象并调用如下内容:
callObject.enqueue(........)
Run Code Online (Sandbox Code Playgroud)
当您调用 enqueue 时,您是否在进行后续网络请求?这是两个网络请求还是第一部分:client.queueCustomer(someString)只是构造将通过发送的对象callObject.enqueue(........)?
提前致谢
好的。这是场景。我有一个用户填写的表单来创建一个 Match 对象。我使用 anIntentService将信息写入后台线程上的文件。如果在boolean中传递了“true”的intenta,则ScoreFile也写入了相应的 a 。GlobalMatch是一个单例对象这里是IntentService代码:
public class WriteMatchService extends IntentService {
private static final String EXTRA_SCORES_FILE = "scores_file";
public static final String REFRESH_MATCH_LIST_INTENT_FILTER = "refresh_match_list";
public static Intent getIntent(Context context, boolean writeScoresFile) {
Intent intent = new Intent(context.getApplicationContext(),
WriteMatchService.class);
intent.putExtra(EXTRA_SCORES_FILE, writeScoresFile);
return intent;
}
public WriteMatchService() {
super("WriteMatchService");
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
boolean writeScoresFile = false;
if (intent != null) {
if (intent.hasExtra(EXTRA_SCORES_FILE)) …Run Code Online (Sandbox Code Playgroud) 我正在使用React 导航库。我编写了一个自定义抽屉菜单并将其添加到导航器的contentComponent配置中。我不知道如何确定自定义菜单中哪个页面/屏幕处于活动状态。这是我的DrawerNavigator代码:
const DrawerNavigator = createDrawerNavigator({
"Search Locations": {
screen: SearchLocationsScreen,
},
"About": {
screen: AboutScreen
},
"Favorites": {
screen: FavoritesScreen
},
"Sign In": {
screen: SignIn
},
}, {
contentComponent: props => <CustomDrawerComponent {...props} />
});
Run Code Online (Sandbox Code Playgroud)
可能需要注意的是,我的DrawerNavigator嵌套在StackNavigator内。我将导航选项导出到一个单独的文件,如下所示:
export default (navigation) => {
const {state} = navigation;
let navOptions = {};
if(state.index === 0){
navOptions.headerRight = (
<TouchableOpacity>
<MaterialIcons
name="my-location"
size={32}
color="#fff"
style={{paddingRight: 10}} />
</TouchableOpacity>
)
}
if (state.isDrawerOpen){ …Run Code Online (Sandbox Code Playgroud) 我正在使用React Navigation 5+. 他们改变了您配置导航器的方式,我正在尝试在我的程序中实现它。我有一个DrawerNavigator顶级导航器。第一个屏幕是StackNavigator几个屏幕。我正在寻找一种方法来防止用户在除第一个屏幕之外的每个屏幕上滑动抽屉。这是我的导航器文件:
const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();
function CheckinStack() {
return (
<Stack.Navigator
initialRouteName={"Loading"}
headerMode={"none"}
>
<Stack.Screen
name={"Search Locations"}
component={SearchLocationsScreen}
options={{gestureEnabled: true}}
/>
<Stack.Screen
name={"Check In Form"}
component={CheckInFormScreen}
options={{gestureEnabled: false}}
/>
<Stack.Screen
name={"Checked In"}
component={CheckedInScreen}
options={{gestureEnabled: false}}
/>
<Stack.Screen
name={"Business Details"}
component={BusinessDetailsScreen}
options={{gestureEnabled: false}}
/>
</Stack.Navigator>
);
}
function MainDrawer() {
return (
<Drawer.Navigator >
<Drawer.Screen name={"Search Locations"} component={CheckinStack}/>
<Drawer.Screen name={"About"} component={AboutScreen}/>
<Drawer.Screen name={"Favorites"} component={FavoritesScreen}/>
<Drawer.Screen name={"Profile"} component={ProfileScreen}/>
<Drawer.Screen …Run Code Online (Sandbox Code Playgroud) navigation-drawer react-native react-navigation stack-navigator