as

Settings
Sign out
Notifications
Alexa
亚马逊应用商店
AWS
文档
Support
Contact Us
My Cases
新手入门
设计和开发
应用发布
参考
支持

KeplerShareableSurfaceView

KeplerShareableSurfaceView

简述

这是一个React Native组件,用于在屏幕上呈现视频帧。只有在使用VideoPlayer组件于预缓冲模式下运行时才使用此组件,在该模式下,可以同时用不同内容对多个播放器进行预缓冲。然后,应用将由onSurfaceViewCreated事件回调传递的表面句柄附加到需要呈现的视频播放器实例。

扩展

构造函数

new KeplerShareableSurfaceView()

new KeplerShareableSurfaceView(props): KeplerShareableSurfaceView

参数

props

SurfaceViewProps

返回值

KeplerShareableSurfaceView

覆盖

React.Component<SurfaceViewProps>.constructor

属性

context

context: unknown

如果使用新的样式上下文,请在类中重新声明,使其成为静态contextTypeReact.ContextType。应与类型注释或静态contextType一起使用。

示例

static contextType = MyContext
// 对于3.7之前的TS:
context!: React.ContextType<typeof MyContext>
// 对于TS 3.7及更高版本:
declare context: React.ContextType<typeof MyContext>

参见

React文档

继承自

React.Component.context


props

readonly props: Readonly<SurfaceViewProps>

继承自

React.Component.props


refs

refs: object

索引签名

[key: string]: ReactInstance

已弃用

参见

旧版React文档

继承自

React.Component.refs


state

state: Readonly<{}>

继承自

React.Component.state


contextType?

static optional contextType: Context<any>

如果设置,this.context将在运行时设置为给定上下文的当前值。

示例

type MyContext = number
const Ctx = React.createContext<MyContext>(0)

class Foo extends React.Component {
  static contextType = Ctx
  context!: React.ContextType<typeof Ctx>
  render () {
    return <>My context's value: {this.context}</>;
  }
}

参见

https://react.dev/reference/react/Component#static-contexttype

继承自

React.Component.contextType

方法

componentDidCatch()?

optional componentDidCatch(error, errorInfo): void

捕获后代组件中生成的异常。未处理的异常将导致整个组件树被卸载。

参数

error

Error

errorInfo

ErrorInfo

返回值

void

继承自

React.Component.componentDidCatch


componentDidUpdate()?

optional componentDidUpdate(prevProps, prevState, snapshot?): void

更新后立即调用。在初始渲染时不会调用。

仅当getSnapshotBeforeUpdate存在且返回非空值时,快照才会存在。

参数

prevProps

Readonly<SurfaceViewProps>

prevState

Readonly<{}>

snapshot?

any

返回值

void

继承自

React.Component.componentDidUpdate


componentWillMount()?

optional componentWillMount(): void

在执行安装操作及和调用Component.render之前立即调用。避免在此方法中引入任何副作用或订阅。

注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。

返回值

void

已弃用

16.3,改用ComponentLifecycle.componentDidMount componentDidMount或构造函数;在React 17中将不再适用

参见

继承自

React.Component.componentWillMount


componentWillReceiveProps()?

optional componentWillReceiveProps(nextProps, nextContext): void

当组件可能收到新属性时调用。即使属性并未更改,React也可能会调用此方法。因此,如果您只想处理更改,那么一定要对新的属性和现有的属性进行比较。

调用Component.setState通常不会触发此方法。

注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。

参数

nextProps

Readonly<SurfaceViewProps>

nextContext

any

返回值

void

已弃用

16.3,改用静态StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps;在React 17中将不再适用

参见

继承自

React.Component.componentWillReceiveProps


componentWillUpdate()?

optional componentWillUpdate(nextProps, nextState, nextContext): void

如果收到新属性或状态,则在进行渲染之前立即调用。在初始渲染时不会调用。

注意:​ 您不能在此处调用Component.setState。

注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。

参数

nextProps

Readonly<SurfaceViewProps>

nextState

Readonly<{}>

nextContext

any

返回值

void

已弃用

16.3,改用getSnapshotBeforeUpdate;在React 17中将不再适用

参见

继承自

React.Component.componentWillUpdate


forceUpdate()

forceUpdate(callback?): void

参数

callback?

() => void

返回值

void

继承自

React.Component.forceUpdate


getSnapshotBeforeUpdate()?

optional getSnapshotBeforeUpdate(prevProps, prevState): any

在React将Component.render渲染结果应用于文档并返回要提供给componentDidUpdate的对象之前运行。对于在Component.render渲染导致发生更改之前保存滚动位置等内容很有用。

注意:此方法的存在会阻止任何已弃用的生命周期事件运行。

参数

prevProps

Readonly<SurfaceViewProps>

prevState

Readonly<{}>

返回值

any

继承自

React.Component.getSnapshotBeforeUpdate


setState()

setState<K>(state, callback?): void

类型参数

K extends never

参数

state
{} (prevState, props) => {} | Pick<{}, K> Pick<{}, K>
callback?

() => void

返回值

void

继承自

React.Component.setState


shouldComponentUpdate()?

optional shouldComponentUpdate(nextProps, nextState, nextContext): boolean

调用以确定属性和状态更改是否应触发重新渲染。

Component始终返回true。PureComponent可对属性和状态进行浅层比较,并在发现任何属性或状态更改时返回true。

如果返回false,则不会调用Component.render、componentWillUpdatecomponentDidUpdate

参数

nextProps

Readonly<SurfaceViewProps>

nextState

Readonly<{}>

nextContext

any

返回值

boolean

继承自

React.Component.shouldComponentUpdate


UNSAFE_componentWillMount()?

optional UNSAFE_componentWillMount(): void

在执行安装操作及和调用Component.render之前立即调用。避免在此方法中引入任何副作用或订阅。

此方法在React 17中仍然有效。

注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。

返回值

void

已弃用

16.3,改用ComponentLifecycle.componentDidMount componentDidMount或构造函数

参见

继承自

React.Component.UNSAFE_componentWillMount


UNSAFE_componentWillReceiveProps()?

optional UNSAFE_componentWillReceiveProps(nextProps, nextContext): void

当组件可能收到新属性时调用。即使属性并未更改,React也可能会调用此方法。因此,如果您只想处理更改,那么一定要对新的属性和现有的属性进行比较。

调用Component.setState通常不会触发此方法。

此方法在React 17中仍然有效。

注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。

参数

nextProps

Readonly<SurfaceViewProps>

nextContext

any

返回值

void

已弃用

16.3,改用静态StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps

参见

继承自

React.Component.UNSAFE_componentWillReceiveProps


UNSAFE_componentWillUpdate()?

optional UNSAFE_componentWillUpdate(nextProps, nextState, nextContext): void

如果收到新属性或状态,则在进行渲染之前立即调用。在初始渲染时不会调用。

注意:​ 您不能在此处调用Component.setState。

此方法在React 17中仍然有效。

注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。

参数

nextProps

Readonly<SurfaceViewProps>

nextState

Readonly<{}>

nextContext

any

返回值

void

已弃用

16.3,改用getSnapshotBeforeUpdate

参见

继承自

React.Component.UNSAFE_componentWillUpdate


Last updated: 2025年10月2日