I am trying to integrate camera-x inside an android fragment in react-native
Here is my native code
class CealScanQrView(context: Context): FrameLayout(context) {
init {
val frameLayoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
layoutParams = frameLayoutParams
setLayoutParams(layoutParams)
setBackgroundColor(Color.parseColor("#5FD3F3"))
preview = PreviewView(context)
preview.id = View.generateViewId()
preview.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
addView(preview)
}
//other non related code
......
}
Instead of Framelayout, I tried using Linearlayout and ConstraintLayout as well but same issue persists
on react-native side, I am using it as follows
const App = () => {
//non-related code here
.....
return (
<SafeAreaView>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
{isCameraPermissionGranted ? (
<CealScanQrViewManager
style={{
// converts dpi to px, provide desired height
height: PixelRatio.getPixelSizeForLayoutSize(200),
// converts dpi to px, provide desired width
width: PixelRatio.getPixelSizeForLayoutSize(200),
}}
ref={ref}
onChange={readQr}
/>
) : (
<View style={{backgroundColor: 'red'}} />
)}
<Text style={{color: 'red', fontSize: 25}}>{firstText}</Text>
<Text style={{color: 'red', fontSize: 25}}>{secondText}</Text>
</SafeAreaView>
);
}
This is how my UI looks
You can see there is space between camera and the first text in red color.
that space is the Framelayout but the camera does not occupy the entire space of Framelayout which I don't understand why
Full source code here
