sk eat
12/31/2024, 1:27 AMsk eat
12/31/2024, 1:27 AMSampleAdBanner
composable is invoked, and an instance of SampleAdFragment
is created with advertisement-related events being tracked. However, the ad is not displayed on the actual screen. (It is suspected that the visibility is set to INVISIBLE or it is not being rendered.)
• Additional Information: SampleAdFragment
works correctly in an XML environment.
Implementation Details
• Ad Banner Implementation: The ad banner is implemented using a Fragment and is bound through the SampleAdBanner
composable in a Compose environment using AndroidViewBinding.
• Lock Screen Characteristics: The activity frequently toggles between background and foreground states. A service detects the screen off event to create the activity in the background.
• Key Composables Used:
◦ `SampleLockScreen`: Composes the entire lock screen UI.
◦ `SampleLockScreenScaffold`: A swipeable scaffold layout.
◦ `SampleAdBanner`: A composable for integrating the ad banner using a Fragment.
Key Code Snippets
@Composable
fun SampleLockScreen() {
Box(modifier = Modifier.fillMaxSize()) {
SampleContent() // This is visible
SampleAdBanner() // However, this is not visible
}
}
@Composable
fun SampleAdBanner(modifier: Modifier = Modifier) {
val fragmentHolder = remember { mutableStateOf<SampleAdFragment?>(null) }
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
AndroidViewBinding(
modifier = modifier,
factory = SampleFragmentContainerBinding::inflate,
) {
fragmentHolder.value = fragmentContainerView.getFragment<SampleAdFragment>()
}
}
class SampleAdFragment : Fragment(R.layout.fragment_sample_ad) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// can't see it, but the events here are aggregated.
}
}
Current Hypotheses
• Modifier Configuration Issue: The size or position of the ad banner might not be set appropriately, causing it not to appear on the screen.
• Compatibility Issue Between Compose and Fragment: There may be issues rendering the UI tree correctly when integrating the Fragment through AndroidViewBinding
.
Question
Is it possible that the Fragment is created but the view is not rendering during the binding process? If so, is there a way to reproduce this issue?