react-native-nitro-modules
Version:
Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI.
31 lines (28 loc) • 862 B
text/typescript
import type { HybridObject } from '../HybridObject'
import { NitroModules } from '../NitroModules'
export function installWorkletsSupport() {
try {
const { registerCustomSerializable } =
require('react-native-worklets') as typeof import('react-native-worklets')
const boxedNitroProxy = NitroModules.box(NitroModules)
registerCustomSerializable({
name: 'nitro.HybridObject',
determine(value): value is HybridObject<{}> {
'worklet'
const nitroProxy = boxedNitroProxy.unbox()
return nitroProxy.isHybridObject(value)
},
pack(value) {
'worklet'
const nitroProxy = boxedNitroProxy.unbox()
return nitroProxy.box(value)
},
unpack(value) {
'worklet'
return value.unbox()
},
})
} catch {
// react-native-worklets not installed.
}
}