当使用包含AppBarLayout(持有ToolBar和TabLayout)和ViewPager(保存片段)作为子项的协调器布局时,我遇到了问题.我希望在向下滚动时隐藏顶部栏,并在向上滚动时显示.但是,当我向下滚动时,状态栏也会向上滚动,顶部栏位于状态图标的正下方,与它们重叠.
我尝试向AppBarLayout和ViewPager添加android:fitsSystemWindows ="true",但没有任何改变.
在使用的代码下方和显示两种状态的快照:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
Redux sagaeventChannel是一个非常优雅的解决方案,可以从组件代码外部连接到外部事件,使它们更简洁、更简洁。一个用例可能是对全局应用程序状态变化做出反应,例如应用程序在前台、后台、不活动......
我担心 React Native 的取消订阅过程。在组件内部,componentWillUnmount是执行取消订阅的地方,因此我们有一些 UI 钩子可以保证我们成功移除侦听器。
例如,当我应用以下代码来跟踪 App 状态更改(活动、非活动或后台)时,我是否会面临内存泄漏?
type NextAppState = 'active' | 'inactive' | 'background';
function createAppStateChannel() {
return eventChannel((emit: (nextState: NextAppState) => mixed) => {
AppState.addEventListener('change', emit);
return () => {
AppState.removeEventListener('change', emit);
};
});
}
export function* appStateListenerSaga(): Generator<*, *, *> {
try {
const appStateChannel = yield call(createAppStateChannel);
while (true) {
const nextAppState: NextAppState = yield take(appStateChannel);
if (nextAppState === 'active') {
// Do something, like syncing with server …Run Code Online (Sandbox Code Playgroud)