react-native - 将 Animated.Value 传递给反应原生的样式组件?
问题描述
如何将 Animated.Value 传递给样式化组件?
每当我取消注释bottom: ${p=>p.bottom};
行时,我都会收到此错误:
NSString 类型的 JSON 值“[object Object]”无法转换为 YGValue。您是否忘记了 % 或 pt 后缀?
这是我的代码:
...
const [value] = useState(new Animated.Value(-100));
return (
<StyledView
as={Animated.View}
bottom={value}
{...props}>
<Button
title={'Show'}
onPress={() => {
Animated.timing(value, {toValue: 0, duration: 300}).start();
}}
/>
<Button
title={'Hide'}
onPress={() => {
Animated.timing(value, {toValue: -100, duration: 300}).start();
}}
/>
</StyledView>
);
...
const StyledView = styled.View`
position: absolute;
height: 200;
bottom: ${p=>p.bottom};
background-color: yellow;
width: 100%;
`;
解决方案
推荐阅读
- javascript - 为什么更新前的mongo db响应值
- unity3d - 在没有 Bolt 的情况下使用统一
- css - Why can't I margin the div, why do I have to margin the child to margin the div?
- ios - saveInBackground (Parse) 抛出错误
- javascript - 用户在 context.switchToHttp().getRequest() nestjs 上未定义
- php - Laravel 8 中未正确添加自定义语言
- c - 将相同的内存与 2 种不同类型的变量一起使用,而不会在 C 中导致未定义的行为
- android - 应用程序 Flutter 中的 Firebase 缓存 .indexOn
- reactjs - 搜索栏未从 github 填充
- python - 我的焦点堆叠算法有什么问题?