You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native应用中Vimeo播放器单标签页全屏功能异常

解决react-native-vimeo-iframe全屏/退出全屏按钮点击异常问题
  • 检查版本兼容性
    旧版本的react-native-vimeo-iframe可能和当前React Native版本存在兼容性问题,导致事件绑定bug。试试升级到最新稳定版:

    npm install react-native-vimeo-iframe@latest
    # 用yarn的话执行 yarn add react-native-vimeo-iframe@latest
    
  • 替换默认按钮,自定义全屏逻辑
    直接禁用组件自带的全屏按钮,通过组件提供的setFullscreen方法和onFullscreenChange回调手动实现控制,稳定性更高:

    import VimeoPlayer from 'react-native-vimeo-iframe';
    import { useState, useRef } from 'react';
    import { TouchableOpacity, Text, View } from 'react-native';
    
    export default function VimeoPlayerPage() {
      const [isFullscreen, setIsFullscreen] = useState(false);
      const playerRef = useRef(null);
    
      const toggleFullscreen = () => {
        playerRef.current?.setFullscreen(!isFullscreen);
      };
    
      return (
        <View style={{ flex: 1 }}>
          <VimeoPlayer
            ref={playerRef}
            videoId="your-video-id-here"
            showFullscreenButton={false} // 隐藏默认按钮
            onFullscreenChange={(status) => setIsFullscreen(status)}
            style={{ flex: 1 }}
          />
          <TouchableOpacity onPress={toggleFullscreen} style={{ padding: 10, backgroundColor: '#ccc' }}>
            <Text>{isFullscreen ? '退出全屏' : '进入全屏'}</Text>
          </TouchableOpacity>
        </View>
      );
    }
    
  • 处理WebView事件拦截问题
    该库底层依赖WebView,可能存在事件冒泡被拦截的情况。给组件外层套个TouchableWithoutFeedback,阻止不必要的触摸事件干扰:

    import { TouchableWithoutFeedback, View } from 'react-native';
    
    // ...
    return (
      <TouchableWithoutFeedback onPress={() => {}}>
        <View style={{ flex: 1 }}>
          <VimeoPlayer
            videoId="your-video-id-here"
            // 其他属性
          />
        </View>
      </TouchableWithoutFeedback>
    );
    
  • 清除WebView缓存
    缓存也可能导致交互异常,试试给组件添加cacheEnabled={false}属性,或者卸载组件时重置WebView实例:

    <VimeoPlayer
      videoId="your-video-id-here"
      cacheEnabled={false}
      // 其他属性
    />
    

内容的提问来源于stack exchange,提问作者kanagaraj gurusamy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 10:05:23