Android fragments 使片段成为react本机错误中的UI组件
当我试图将片段作为UI组件时,我遇到了一个问题 在react native中首次渲染时,下面的代码运行良好,但当组件重新渲染应用程序将因Android fragments 使片段成为react本机错误中的UI组件,android-fragments,react-native-android,Android Fragments,React Native Android,当我试图将片段作为UI组件时,我遇到了一个问题 在react native中首次渲染时,下面的代码运行良好,但当组件重新渲染应用程序将因transaction?而崩溃时。替换(R.id.id\u empty\u content,EmptyFragment(),“EmptyFragment”)。错误显示没有查看片段的id\u empty\u内容。当组件取消装载时,片段是否未被销毁,但id\u empty\u内容已消失?希望有人能帮我解决这个问题 视图管理器: class EmptyFragment
transaction?而崩溃时。替换(R.id.id\u empty\u content,EmptyFragment(),“EmptyFragment”)
。错误显示没有查看片段的id\u empty\u内容。当组件取消装载时,片段是否未被销毁,但id\u empty\u内容已消失?希望有人能帮我解决这个问题
视图管理器:
class EmptyFragmentManager : SimpleViewManager<RelativeLayout>() {
override fun createViewInstance(reactContext: ThemedReactContext?): RelativeLayout{
val manager = reactContext?.currentActivity?.fragmentManager
val transaction = manager?.beginTransaction()
val view = LayoutInflater.from(reactContext).inflate(R.layout.layout_empty, null, false) as RelativeLayout
transaction?.replace(R.id.id_empty_content, EmptyFragment(), "EmptyFragment")
transaction?.commit()
return view
}
override fun getName(): String = "Empty"
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/id_empty_content"></FrameLayout>
</RelativeLayout>
import React, { Component } from 'react'
import { StyleSheet, Platform } from 'react-native'
import { Container, } from 'native-base'
import { colors, constants } from '../config'
import { SessionList, Empty } from '../components/sdk'
const styles = StyleSheet.create({
container: {
flex: 1,
position: 'relative',
backgroundColor: colors.white,
},
session_list: {
flex: 1,
marginTop: constants.STATUS_BAR_HEIGHT,
},
})
export class InfoListPage extends Component {
render () {
return (
<Container style={styles.container}>
{Platform.OS === 'ios' ? null : <Empty style={styles.session_list}/>}
</Container>
)
}
}
java.lang.IllegalArgumentException: No view found for id 0x7f100acf (cn.samuel.pro:id/id_empty_content) for fragment EmptyFragment{4d538b #0 id=0x7f100acf EmptyFragment}