Javascript 如何在react native中更改动态列表视图中的字体大小?

Javascript 如何在react native中更改动态列表视图中的字体大小?,javascript,react-native,native-base,Javascript,React Native,Native Base,我对代码有奇怪的问题 当我动态更改字体大小时,静态listItem文本将更改。但是动态列表项文本没有改变 代码如下: <List style={{ backgroundColor: "#3F51B5", flex: 1, justifyContent: "center", alignItems: "center" }}

我对代码有奇怪的问题

当我动态更改字体大小时,静态listItem文本将更改。但是动态列表项文本没有改变

代码如下:

 <List
            style={{
              backgroundColor: "#3F51B5",
              flex: 1,
              justifyContent: "center",
              alignItems: "center"
            }}
          >
            <ListItem>
              <Text
                style={{
                  fontSize: this.state.fontSize,
                  textAlign: "center",
                  color: "white"
                }}
              >
               Hello
              </Text>
            </ListItem>
          </List>

你好
上述代码中的字体大小更改正在工作。

<List
            dataArray={this.state.data}
            style={{ backgroundColor: "white" }}
            renderRow={item => (
              <ListItem
                noBorder
                style={{
                  flex: 1,
                  justifyContent: "center",
                  alignItems: "center"
                }}
              >
                <Text
                  style={
                    {
                      fontSize: this.state.fontSize,
                      textAlign: "center"
                    }
                  }
                >
                  {item.line}
                </Text>
              </ListItem>
            )}
          />
(
{item.line}
)}
/>
上述代码中的字体大小更改无效。

<List
            dataArray={this.state.data}
            style={{ backgroundColor: "white" }}
            renderRow={item => (
              <ListItem
                noBorder
                style={{
                  flex: 1,
                  justifyContent: "center",
                  alignItems: "center"
                }}
              >
                <Text
                  style={
                    {
                      fontSize: this.state.fontSize,
                      textAlign: "center"
                    }
                  }
                >
                  {item.line}
                </Text>
              </ListItem>
            )}
          />

有什么问题?任何人都请帮忙。这是一个奇怪的问题。静态列表文本字体大小正在更改,但动态不变。

问题在于,只有在dataArray属性发生更改时,才会更新Native Base中的列表组件。因此列表无法识别
this.state.fontSize
中的更新,因此不会重新渲染

Native Base还警告说
List
不适用于动态列表,并建议使用标准的react Native
FlatList
组件:

注意:列表已弃用。使用列表生成动态列表是非常困难的 不鼓励。有关渲染列表的更高级实现 动态地,看看nativebase教程。改用平面列表

更改FlatList的列表时,您可以特别声明
this.state.fontSize
应通过将组件传递给
extraData
属性来更新组件

(
{item.line}
)}
/>