KeplerShareableSurfaceView
简述
这是一个React Native组件,用于在屏幕上呈现视频帧。只有在使用VideoPlayer组件于预缓冲模式下运行时才使用此组件,在该模式下,可以同时用不同内容对多个播放器进行预缓冲。然后,应用将由onSurfaceViewCreated事件回调传递的表面句柄附加到需要呈现的视频播放器实例。
扩展
Component<SurfaceViewProps>
构造函数
new KeplerShareableSurfaceView()
new KeplerShareableSurfaceView(
props):KeplerShareableSurfaceView
参数
props
返回值
覆盖
React.Component<SurfaceViewProps>.constructor
属性
context
context:
unknown
如果使用新的样式上下文,请在类中重新声明,使其成为静态contextType的React.ContextType。应与类型注释或静态contextType一起使用。
示例
static contextType = MyContext
// 对于3.7之前的TS:
context!: React.ContextType<typeof MyContext>
// 对于TS 3.7及更高版本:
declare context: React.ContextType<typeof MyContext>
参见
继承自
React.Component.context
props
readonlyprops:Readonly<SurfaceViewProps>
继承自
React.Component.props
refs
refs:
object
索引签名
[key: string]: ReactInstance
已弃用
参见
继承自
React.Component.refs
state
state:
Readonly<{}>
继承自
React.Component.state
contextType?
staticoptionalcontextType: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()?
optionalcomponentDidCatch(error,errorInfo):void
捕获后代组件中生成的异常。未处理的异常将导致整个组件树被卸载。
参数
error
Error
errorInfo
ErrorInfo
返回值
void
继承自
React.Component.componentDidCatch
componentDidUpdate()?
optionalcomponentDidUpdate(prevProps,prevState,snapshot?):void
更新后立即调用。在初始渲染时不会调用。
仅当getSnapshotBeforeUpdate存在且返回非空值时,快照才会存在。
参数
prevProps
Readonly<SurfaceViewProps>
prevState
Readonly<{}>
snapshot?
any
返回值
void
继承自
React.Component.componentDidUpdate
componentWillMount()?
optionalcomponentWillMount():void
在执行安装操作及和调用Component.render之前立即调用。避免在此方法中引入任何副作用或订阅。
注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。
返回值
void
已弃用
16.3,改用ComponentLifecycle.componentDidMount componentDidMount或构造函数;在React 17中将不再适用
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
React.Component.componentWillMount
componentWillReceiveProps()?
optionalcomponentWillReceiveProps(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中将不再适用
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
React.Component.componentWillReceiveProps
componentWillUpdate()?
optionalcomponentWillUpdate(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中将不再适用
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
React.Component.componentWillUpdate
forceUpdate()
forceUpdate(
callback?):void
参数
callback?
() => void
返回值
void
继承自
React.Component.forceUpdate
getSnapshotBeforeUpdate()?
optionalgetSnapshotBeforeUpdate(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()?
optionalshouldComponentUpdate(nextProps,nextState,nextContext):boolean
调用以确定属性和状态更改是否应触发重新渲染。
Component始终返回true。PureComponent可对属性和状态进行浅层比较,并在发现任何属性或状态更改时返回true。
如果返回false,则不会调用Component.render、componentWillUpdate和componentDidUpdate。
参数
nextProps
Readonly<SurfaceViewProps>
nextState
Readonly<{}>
nextContext
any
返回值
boolean
继承自
React.Component.shouldComponentUpdate
UNSAFE_componentWillMount()?
optionalUNSAFE_componentWillMount():void
在执行安装操作及和调用Component.render之前立即调用。避免在此方法中引入任何副作用或订阅。
此方法在React 17中仍然有效。
注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。
返回值
void
已弃用
16.3,改用ComponentLifecycle.componentDidMount componentDidMount或构造函数
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
React.Component.UNSAFE_componentWillMount
UNSAFE_componentWillReceiveProps()?
optionalUNSAFE_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
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
React.Component.UNSAFE_componentWillReceiveProps
UNSAFE_componentWillUpdate()?
optionalUNSAFE_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
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
React.Component.UNSAFE_componentWillUpdate
Last updated: 2025年10月2日

