小编Sli*_*idy的帖子

navigation.setOptions 不改变

我正在使用反应导航器创建屏幕,但当屏幕打开时我无法更改标题栏的选项

我的代码(App.js):

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator screenOptions={{
        headerTitleAlign: 'center',
        headerTitle: props => <LogoTitle {...props} />,
        headerRight: props => <HeaderRight {...props} />,
        headerStyle: {
          backgroundColor: '#F46A0D'
        },
        headerTintColor: '#fff',
      }}>
        <Stack.Screen name="Search" component={SearchScreen}/>
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default App;
Run Code Online (Sandbox Code Playgroud)

我的 SearchScreen.js:

import React from 'react'
import { Text, View } from 'react-native'
import { Button } from 'react-native-paper'

const SearchScreen = ({ navigation }) => {
    navigation.setOptions = {
        headerTitle: props => <TextInput {...props} placeholder="Search" placeholderTextColor="#FFFF" style={{ …
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation

7
推荐指数
2
解决办法
3万
查看次数

在字符串中间插值

我想插入一个字符串的中间,但我不能使用String.Format,因为该字符串包含{}大括号.

这是我到目前为止所尝试的:

string code = "(function(){var myvariable = $"{variableToBeInterpolated}"});"
Run Code Online (Sandbox Code Playgroud)

返回:)预期; 预期

编辑:我尝试了下面的代码片段,插值现在正在工作,但代码不会在浏览器中执行.

"(function(){var myvariable=" + $"{myvariable c#}" + ")});"
Run Code Online (Sandbox Code Playgroud)

c# string-interpolation

2
推荐指数
1
解决办法
144
查看次数

为什么使用异步函数进行reduce只返回最后一个对象

我试图为数组中的所有水果设置随机数,并返回一个包含减速器中具有异步函数的所有水果的对象,但只返回数组的最后一个元素

(async () =>
  console.log(
    await [("apple", "banana", "orange")].reduce(async (o, fruit) => {
      const random_number = await new Promise((resolve) => setTimeout(() => resolve(Math.random()), 200));
      return { ...o, [fruit]: random_number };
    }, {})
  ))();
Run Code Online (Sandbox Code Playgroud)

javascript

0
推荐指数
1
解决办法
756
查看次数