首页 \ 问答 \ React Native - 动画功能组件(React Native - Animated Functional Components)

React Native - 动画功能组件(React Native - Animated Functional Components)

我喜欢React Native动画API,但它与我编写完全无状态功能组件的首选组件方式有很大冲突。

以此组件为例。 如何在不恢复类语法和状态变量来驱动图像样式的情况下使图像动画化?

const Logo = () => (
  <View style={styles.container}>
    <View style={styles.imageContainer}>
      <Animated.Image 
        resizeMode='contain'
        style={styles.image}
        source={require(img/sample.png')}
      />
    </View>
  </View>
)

export default Logo

I love the React Native animated API but it conflicts heavily with my preferred way of writing components which is completely stateless functional components.

Take this component as an example. How would I make the Image animated without reverting to class syntax and a state variable to drive the Image style?

const Logo = () => (
  <View style={styles.container}>
    <View style={styles.imageContainer}>
      <Animated.Image 
        resizeMode='contain'
        style={styles.image}
        source={require(img/sample.png')}
      />
    </View>
  </View>
)

export default Logo

原文:https://stackoverflow.com/questions/44961099
更新时间:2023-05-07 11:05

最满意答案

if(&queue->head == NULL){

在此行中,您将检查fifo元素head的地址。 这可能不是你想要的。 相反,您要检查指针的值是否有效:

if(queue->head == NULL){

另请注意,您必须使用正确的值启动fifo:

fifo f;
f.head = 0;
f.tail = 0;
Enqueue( &f, 1 );

你应该检查malloc是否实际返回一个有效的地址:

temp = (fifo_element*)malloc(sizeof(fifo_element));
if(temp == NULL){
     /* insufficient memory, print error message, return error, etc */
} else {
     /* your code */
}

if(&queue->head == NULL){

In this line you check the address of the element head in your fifo. This is probably not what you want. Instead, you want to check whether the value of your pointer is valid:

if(queue->head == NULL){

Also keep in mind that you have to initiate the fifo with the correct values:

fifo f;
f.head = 0;
f.tail = 0;
Enqueue( &f, 1 );

And you should check whether malloc actually returns a valid address:

temp = (fifo_element*)malloc(sizeof(fifo_element));
if(temp == NULL){
     /* insufficient memory, print error message, return error, etc */
} else {
     /* your code */
}

相关问答

更多
  • 使用memcached实现FIFO队列是否合理? 是的 实用没有 。 以下是python的一个非常基本的实现。 from pylibmc import Client class Queue: """A sample implementation of a First-In-First-Out data structure.""" def __init__(self): self.in_ptr = 0 self.out_ptr = 0 ...
  • 如果只有三个优先级值(或者更一般的固定优先级范围),为什么不能实现三个单独的队列并编写一个根据优先级将封装函数添加/删除到特定队列的封装函数? If you have only three values of priority (or in more general - fixed range of priorities) why can't you implement three separate queues and write a wrapper functions that depending on ...
  • 是的,它会给出分段错误。 if你正在访问head->next 。 head只是struct node类型的指针。 首先分配内存空间,然后访问该字段。 现在你正在访问(head->next) ,这是内存中的一些不合适的地址,内核给进程带来了“分段错误”。 例如,do struct node* head = malloc(sizeof(struct node)); 然后可以访问head->next 。 Yes ofcourse it will give segmentation fault. In if con ...
  • 当已经有std :: list的时候,是否有任何实际的实际优势来实现我自己的双向链表? 可能不会。 我可以让自己的某件事更有效率吗? 也许 - 取决于任务。 例如,您可能只需要一个单链表,这可能最终会变得更快。 或者std :: list在过去的几年中已经得到了很多的改进,在大多数情况下它是最佳的双向链表实现? 大概。 所有这些东西的最佳答案可能是“在标准实现不起作用之前使用标准实现,然后弄清楚你将要做些什么。” is there any actual real-world advantage of imp ...
  • 你还必须分配: char *artist; char *album; char *song_title; char *release_date; 分配struct MP3时,它也不会分配内部参数。 您可以像这样修改create()函数: temp =(struct MP3 *)malloc(1*sizeof(struct MP3)); #define MAX_LEN 100 temp->artist =(char *)malloc(MAX_LEN*sizeof(char)); temp->album =( ...
  • if(&queue->head == NULL){ 在此行中,您将检查fifo元素head的地址。 这可能不是你想要的。 相反,您要检查指针的值是否有效: if(queue->head == NULL){ 另请注意,您必须使用正确的值启动fifo: fifo f; f.head = 0; f.tail = 0; Enqueue( &f, 1 ); 你应该检查malloc是否实际返回一个有效的地址: temp = (fifo_element*)malloc(sizeof(fifo_element)); ...
  • ON: - >运算符可以重载,因此开发环境无法确定如何处理它。 如果您真的想要自动完成,可以执行以下操作(暂时或永久)。 // IMPORTANT. Make sure "head" is not null before you do it! Node &headNode(*head); // Create a reference headNode.next = tail; // Use TAB or CTRL+SPACE or whatever here after dot OFF:我查看了您的代码并 ...
  • 将值(如指针)传递给例程时,为了使例程设置该值,您必须传递其地址 。 因此,这一行: createQueue(list); 应该: createQueue(&list); 如果您想要createQueue来设置变量的值。 你还需要: void createQueue(LinkedList** list) { *list = (LinkedList*) calloc(1, sizeof(LinkedList)); } 不要担心 - 每个C程序员都会在某些时候犯这个错误。 有关更多信息,请搜索“按 ...
  • while (current != NULL) { previous = current; current = current->next; } *value = current->value; 在while循环结束时,current为NULL。 您希望在存在下一个元素时进行迭代。 因此,您应该替换它 while (current->next != NULL) while (current != NULL) { previous = current; current ...
  • 当队列为空时,不要将n->prev设置为enqueue当队列不为空时,也不要设置n->next 。 如果队列有超过2个元素,则队列会破坏队列,如果队列只有一个元素,则会崩溃。 这是一个更正版本: void enqueue(Queue_ptr s, element e) { DN_ptr n = (DN_ptr)malloc(sizeof(DLLNode)); n->e = e; n->next = NULL; if (s->front == NULL) { n ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)