I get ratio
using this.Camera!.getSupportedRatiosAsync()
then pass it to this.Camera!.getAvailablePictureSizesAsync(ratio)
.
This should not throw error, but I got an error every time I tried.
My code are below
class Screen extends React.Component {
render() {
return (
<Camera
ref={this.setRef as any}
style={_cameraStyle}
type={type}
// zoom={zoom}
ratio={_ratio}
flashMode={Camera.Constants.FlashMode.off}
autoFocus={Camera.Constants.AutoFocus.on}
whiteBalance={Camera.Constants.WhiteBalance.auto}
pictureSize={pictureSize}
onCameraReady={this.updateStateForCameraProps}
/>
)
}
updateStateForCameraProps = () => {
if (Platform.OS === 'android') {
InteractionManager.runAfterInteractions(async () => {
const ratios = await this.Camera!.getSupportedRatiosAsync()
const [ratio, dimensions] = pickRatio_calcDimensions(ratios)
console.log({ ratios, ratio })
const sizes = await this.Camera!.getAvailablePictureSizesAsync(ratio)
this.setState({ pictureSize: sizes[0], cameraStyle: dimensions })
console.log({ sizes })
})
}
}
}
function pickRatio_calcDimensions(ratios: string[]): [string, ViewStyle] {
const ratio = ratios[getIndexOfMinRatio(ratios)]
const [height, width] = getDimensionsFromRatio(ratio)
const dimensions: ViewStyle = { width: windowWidth, height: (windowWidth * height) / width }
return [ratio, dimensions]
}
and console log shows
Object {
"ratio": "11:9",
"ratios": Array [
"4:3",
"5:3",
"11:9",
"16:9",
"30:17",
],
}
[Unhandled promise rejection: Error: getAvailablePictureSizes -- unexpected error -- Attempt to invoke interface method 'int java.util.SortedSet.size()' on a null object reference]
- node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:146:41 in createErrorFromErrorData
- node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:95:55 in <unknown>
- ... 5 more stack frames from framework internals
It works if ratio = "4:3"
, but not ratio = "11:9"
.
I didn’t try others ( “5:3”, “16:9”, “30:17” ).
Is there any solution for this?