Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions example/react-native/__tests__/BottomTabs.drawer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Text, View } from 'react-native';
import { StyleSheet, Text, View } from 'react-native';
import ReactTestRenderer, { act } from 'react-test-renderer';

jest.mock(
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('native drawer slots', () => {
expect(drawer.props.enabled).toBe(false);
});

it('forwards only the settled boolean, with native progress absent from the API', async () => {
it('forwards only the settled boolean, with native progress off unless requested', async () => {
const onChange = jest.fn();
await act(() => {
renderer = ReactTestRenderer.create(
Expand All @@ -90,11 +90,54 @@ describe('native drawer slots', () => {
const drawer = renderer!.root.findByType('NativeDrawer' as any);
expect(drawer.props.hapticFeedbackEnabled).toBe(true);
expect(drawer.props.swipeEnabled).toBe(true);
// The menu slot lays out at the native drawer width.
expect(
StyleSheet.flatten((drawer.children[0] as any).props.style).width,
).toBe('80%');
expect(drawer.props.progressEventsEnabled).toBe(false);
expect(drawer.props.onDrawerProgress).toBeUndefined();
expect(drawer.props.colorScheme).toBeUndefined();
act(() => drawer.props.onDrawerOpenChange({ nativeEvent: { open: true } }));
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(true);
});

it('passes progress handlers, a replacement host and the color scheme to native as is', async () => {
const onProgress = jest.fn();
const renderScene = jest.fn(() => <View />);
const enabledByCommit: boolean[] = [];
const Host = (
props: React.PropsWithChildren<{ progressEventsEnabled?: boolean }>,
) => {
enabledByCommit.push(!!props.progressEventsEnabled);
return <View testID="drawer-host">{props.children}</View>;
};
await act(() => {
renderer = ReactTestRenderer.create(
<BottomTabs
navigationState={{ index: 0, routes: [{ key: 'home' }] }}
renderScene={renderScene}
onIndexChange={() => {}}
renderDrawerContent={menu}
onDrawerProgress={onProgress}
drawerHostComponent={Host as any}
drawerColorScheme="dark"
/>,
);
});
expect(renderer!.root.findAllByType('NativeDrawer' as any)).toHaveLength(0);
const host = renderer!.root.findByType(Host);
// Off during the mount commit, so native's current-position event is
// sent once the host and its handler are attached.
expect(enabledByCommit).toEqual([false, true]);
expect(host.props.progressEventsEnabled).toBe(true);
// That second commit re-renders only the host, not the tabs.
expect(renderScene).toHaveBeenCalledTimes(1);
expect(host.props.onDrawerProgress).toBe(onProgress);
expect(host.props.colorScheme).toBe('dark');
expect(renderer!.root.findByProps({ testID: 'menu-content' })).toBeTruthy();
});

it('Web omits the menu and returns only the foreground', async () => {
await act(() => {
renderer = ReactTestRenderer.create(
Expand Down
1 change: 1 addition & 0 deletions example/react-native/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ target 'example' do
pod 'react-native-pager-view', :path => '../../../node_modules/@onekeyfe/react-native-pager-view', :testspecs => ['Tests']
pod 'OneKeyTextInput', :path => '../../../node_modules/@onekeyfe/react-native-text-input', :testspecs => ['Tests']
pod 'react-native-native-list', :path => '../../../node_modules/@onekeyfe/react-native-native-list', :testspecs => ['Tests']
pod 'react-native-bottom-tabs', :path => '../../../node_modules/@onekeyfe/react-native-bottom-tabs', :testspecs => ['Tests']
pod 'PerpDepthBar', :path => '../../../node_modules/@onekeyfe/react-native-perp-depth-bar', :testspecs => ['Tests']
pod 'ReactNativeBundleCrypto', :path => '../../../node_modules/@onekeyfe/react-native-bundle-crypto', :testspecs => ['Tests']
pod 'ReactNativeCaptureProtection', :path => '../../../node_modules/@onekeyfe/react-native-capture-protection', :testspecs => ['Tests']
Expand Down
29 changes: 27 additions & 2 deletions example/react-native/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,30 @@ PODS:
- ReactCommon/turbomodule/core
- ReactNativeDependencies
- Yoga
- react-native-bottom-tabs/Tests (6.7.0-26):
- hermes-engine
- OneKeyImage
- RCTRequired
- RCTTypeSafety
- React-bridging
- React-Core
- React-Core-prebuilt
- React-cxxstableapi
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-jsi
- React-NativeModulesApple
- React-RCTFabric
- React-renderercss
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/core
- ReactNativeDependencies
- Yoga
- react-native-native-list (6.7.0-26):
- hermes-engine
- NitroModules
Expand Down Expand Up @@ -3311,6 +3335,7 @@ DEPENDENCIES:
- React-microtasksnativemodule (from `../../../node_modules/react-native/ReactCommon/react/nativemodule/microtasks`)
- React-mutationobservernativemodule (from `../../../node_modules/react-native/ReactCommon/react/nativemodule/mutationobserver`)
- "react-native-bottom-tabs (from `../../../node_modules/@onekeyfe/react-native-bottom-tabs`)"
- "react-native-bottom-tabs/Tests (from `../../../node_modules/@onekeyfe/react-native-bottom-tabs`)"
- "react-native-native-list (from `../../../node_modules/@onekeyfe/react-native-native-list`)"
- "react-native-native-list/Tests (from `../../../node_modules/@onekeyfe/react-native-native-list`)"
- "react-native-pager-view (from `../../../node_modules/@onekeyfe/react-native-pager-view`)"
Expand Down Expand Up @@ -3739,7 +3764,7 @@ SPEC CHECKSUMS:
React-Mapbuffer: a2dae4f2cb335ebb97f2240494d0c2bab84cd339
React-microtasksnativemodule: 8b3aaa5f3b907ecf071b105589868d9f027a448d
React-mutationobservernativemodule: 11d77d3f7360578f07847843544ada23cc473049
react-native-bottom-tabs: 31c6a231936155254baa3a09c6e76a1cae887fde
react-native-bottom-tabs: b42bb7227d2d7870a8ca66513bb44186fe76368f
react-native-native-list: f7c9cacff8abdbd12e7405f5ff855098698dcb4b
react-native-pager-view: 03d14fbd70b2e1edbdc6dda3ab3b9c213d1e6774
react-native-safe-area-context: 839ca66874035361e526a8bcb1bfe7c2076c5c0d
Expand Down Expand Up @@ -3811,6 +3836,6 @@ SPEC CHECKSUMS:
TcpSocket: c8d79a8794cc9848513718044ceee976d8bcf6f0
Yoga: d1c536142c5ff8ec8cd856ab2a7c227a1d875c8e

PODFILE CHECKSUM: 6dbd008521e902b8ae039b8440e066a762f0955e
PODFILE CHECKSUM: f3f249fd79ae24990015132b000a41da6eab78e2

COCOAPODS: 1.16.2
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class BottomTabsDrawerManager : ViewGroupManager<BottomTabsDrawerView>(),
DrawerOpenChangeEvent(UIManagerHelper.getSurfaceId(context), view.id, open),
)
}
view.onDrawerProgress = { progress ->
UIManagerHelper.getEventDispatcherForReactTag(context, view.id)?.dispatchEvent(
DrawerProgressEvent(UIManagerHelper.getSurfaceId(context), view.id, progress),
)
}
return view
}

Expand All @@ -36,6 +41,7 @@ class BottomTabsDrawerManager : ViewGroupManager<BottomTabsDrawerView>(),
override fun needsCustomLayoutForChildren() = true
override fun onDropViewInstance(view: BottomTabsDrawerView) {
view.onDrawerOpenChange = null
view.onDrawerProgress = null
view.dispose()
super.onDropViewInstance(view)
}
Expand All @@ -45,6 +51,8 @@ class BottomTabsDrawerManager : ViewGroupManager<BottomTabsDrawerView>(),
override fun setSwipeEnabled(view: BottomTabsDrawerView, value: Boolean) { view.swipeEnabled = value }
override fun setHapticFeedbackEnabled(view: BottomTabsDrawerView, value: Boolean) { view.drawerHapticFeedbackEnabled = value }
override fun setBottomBarHeight(view: BottomTabsDrawerView, value: Double) { view.bottomBarHeight = value.toFloat() }
override fun setColorScheme(view: BottomTabsDrawerView, value: String?) { view.colorScheme = value ?: "system" }
override fun setProgressEventsEnabled(view: BottomTabsDrawerView, value: Boolean) { view.progressEventsEnabled = value }
}

private class DrawerOpenChangeEvent(surfaceId: Int, tag: Int, private val open: Boolean) :
Expand All @@ -53,3 +61,10 @@ private class DrawerOpenChangeEvent(surfaceId: Int, tag: Int, private val open:
override fun canCoalesce() = false
override fun getEventData() = Arguments.createMap().apply { putBoolean("open", open) }
}

// Coalescable: a JS listener only needs the latest position per frame.
private class DrawerProgressEvent(surfaceId: Int, tag: Int, private val progress: Float) :
Event<DrawerProgressEvent>(surfaceId, tag) {
override fun getEventName() = "onDrawerProgress"
override fun getEventData() = Arguments.createMap().apply { putDouble("progress", progress.toDouble()) }
}
Loading
Loading