Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP feat(Android): support modal stack presentation #1974

Draft
wants to merge 102 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
c2d9463
TOREVERT: App.js & Test1649 temp changes
kkafar Sep 11, 2023
9b3c90c
Add stub ScreenModalFragment
kkafar Sep 11, 2023
dcd4373
Implement ScreenModalFragment.fragment
kkafar Sep 11, 2023
007b19a
TOREVERT: change stackPresentation in JS example
kkafar Sep 11, 2023
5a690fc
Use ScreenModalFragment wheen screen has modal stack presentation set
kkafar Sep 11, 2023
a6ffed8
Add dependency on material theme 3 and use it in TestExample (potenti…
kkafar Sep 11, 2023
7ff64cc
linter
kkafar Sep 11, 2023
449b2b9
TOREVERT: Bump native deps & kotlin version in TestsExample & lib
kkafar Sep 11, 2023
8554c41
Display modal
kkafar Sep 12, 2023
47b1bcf
Make StackPresentation.MODAL temporarily transparent to make sure the…
kkafar Sep 12, 2023
55d57cb
Allow for dismissal
kkafar Sep 12, 2023
9d320c9
Refactor ScreenStack.rootScreen property impl
kkafar Sep 13, 2023
81d6744
Go back button on Second screen in Test1649 (in TE)
kkafar Sep 13, 2023
75986e2
Attempt to dismiss modal via container dismiss method
kkafar Sep 13, 2023
6dfbee1
TOREVERT(manual): Modify Test1649
kkafar Sep 13, 2023
5b103b1
TOREVERT: Log upon receiving native events on JS side
kkafar Sep 13, 2023
8706e6b
Bring ScreenModalFragment up to speed with main
kkafar Sep 15, 2023
2a3815b
Managed to present the fragment modally
kkafar Sep 19, 2023
9171cc3
TOREVERT: temporarily disable custom stack animations
kkafar Sep 20, 2023
e9ebb88
Kotlinize implementation of `ScreenStack.adapt` method
kkafar Sep 20, 2023
e37055e
Play around with animation
kkafar Sep 20, 2023
9ed55b7
Stash changes in modal fragment
kkafar Sep 20, 2023
6e0036e
Move `recycleView` method to a `ext` module
kkafar Sep 21, 2023
acac110
Recycle screen before adding it to modal layout
kkafar Sep 21, 2023
9c1ba79
Another stash of changes :facepalm:
kkafar Sep 25, 2023
7110e03
Set behaviour on screen instead of using dedicated fragment type for …
kkafar Nov 8, 2023
7c50989
Some options for the modal
kkafar Nov 14, 2023
8cb8d05
Improve view extensions
kkafar Nov 19, 2023
85df811
Rename dismiss -> dismissFromContainer
kkafar Nov 19, 2023
256fa71
Add more comments into interfaces
kkafar Nov 19, 2023
1d6b1fd
Present 'modal' modally & formSheet as standard bottom sheet
kkafar Nov 20, 2023
a64a400
Stubs, tryGetContext / tryGetActivity, retrieve few props from JS
kkafar Nov 20, 2023
de0974b
Merge branch 'main' into @kkafar/android-modal-refactor-4
kkafar Nov 20, 2023
bd936c9
MAKE DISMISSAL WORK ON MODAL SHEET
kkafar Nov 20, 2023
49db846
Throw when fragmentRef.get == null
kkafar Nov 20, 2023
e5b8e95
Clip bottomsSheet to outline making corner shape visible
kkafar Nov 20, 2023
541ae85
Throw better error message on fragment restoration
kkafar Nov 20, 2023
89aaec1
Add some important comments
kkafar Nov 20, 2023
474d1d7
Cleanup
kkafar Nov 20, 2023
c531509
Enable gesture handling in modal view
kkafar Nov 23, 2023
e310d08
Cleanup ModalRootView & nested scroll view compliance
kkafar Nov 24, 2023
737ee01
Add nestedScrollView prop for ScrollView
kkafar Nov 24, 2023
bbc836a
Attempt to enforce detent based on props
kkafar Nov 24, 2023
fc0525a
Leftover debugging setup
kkafar Nov 24, 2023
5c9dcc0
Comment on STATE_HALF_EXPANDED
kkafar Nov 24, 2023
42bcabd
Cleanup example
kkafar Nov 24, 2023
5a5fb5f
Experiment with dimmign view & drag handle
kkafar Nov 28, 2023
800bb08
Stash gesture handling changes
kkafar Dec 1, 2023
8bc4010
Various experiments with making dimming view work
kkafar Dec 7, 2023
082c3f8
Merge branch 'main' into @kkafar/android-modal-refactor-4
kkafar Dec 7, 2023
2b7546e
Changes for dimming view animation
kkafar Dec 12, 2023
d1f4e32
Stash changes
kkafar Dec 12, 2023
7168f7e
Stash all changes again
kkafar Jan 2, 2024
ac2dd74
Merge branch 'main' into @kkafar/android-modal-refactor-4
kkafar Jan 2, 2024
b2ffaf9
Add some comment for screen stack
kkafar Jan 2, 2024
712593d
Whatever
kkafar Jan 2, 2024
41452de
Merge branch 'main' into @kkafar/android-modal-refactor-4
kkafar Jan 2, 2024
409a410
Fix merge issues
kkafar Jan 3, 2024
6acfd36
Naming convention of member fields in ScreensCoordinatorLayout
kkafar Jan 3, 2024
50db708
Resolve leftover merge conflicts
kkafar Jan 3, 2024
f157497
Cleanup ScreenStackFragment a bit
kkafar Jan 3, 2024
eaa6fe3
Set corner radius in TE
kkafar Jan 3, 2024
77bdbe9
Bring back gesture support for standard bottom sheet (see details for
kkafar Jan 3, 2024
f852bd8
Debug & fix logic responsible for dimming view animation
kkafar Jan 4, 2024
e4e1f88
Allow for navigation to screens above modals
kkafar Jan 5, 2024
82b50f1
Improve behaviour when navigating back to screen with modal
kkafar Jan 5, 2024
b526b63
Native support for closing sheet when touched outside
kkafar Jan 5, 2024
2b257fa
Improve gesture handling on dimming view
kkafar Jan 5, 2024
c372009
Update TS types of sheetAllowedDetents & sheetLargestUndimmedDetent p…
kkafar Jan 7, 2024
49b5ad6
sheetInitialDetent -> sheetInitialState
kkafar Jan 7, 2024
700d46e
Update ScreenNativeComponent spec
kkafar Jan 7, 2024
7b4ed40
Update view manager interfaces for paper
kkafar Jan 7, 2024
612ada8
Bring back functionality of setting sheet height based on fraction pa…
kkafar Jan 7, 2024
86307aa
Check against empty array on native side
kkafar Jan 7, 2024
00d50b2
Cleanup ScreenStackFragment a bit
kkafar Jan 7, 2024
c442b25
Bring back support for dimming view animation
kkafar Jan 7, 2024
426bee8
Remove unused function
kkafar Jan 8, 2024
c3abf7c
Update TestExample to use new API
kkafar Jan 8, 2024
20a7ae6
Add react-versioned files
kkafar Jan 8, 2024
1a0653d
Remove RNSModalRootView.kt from main source set
kkafar Jan 8, 2024
6bda77c
Revert "Add react-versioned files"
kkafar Jan 8, 2024
2fe8144
Revert "Remove RNSModalRootView.kt from main source set"
kkafar Jan 8, 2024
57f0b43
Temporarily remove modal functionality
kkafar Jan 8, 2024
f8e9baf
Fix 3-level detet
kkafar Jan 8, 2024
cadde6a
Update TE
kkafar Jan 8, 2024
dafca03
Make ScreensCoordinatorLayout transparent to gestures
kkafar Jan 8, 2024
4dea550
Improve dimming view behaviour a bit
kkafar Jan 8, 2024
4f47012
Small renaming
kkafar Jan 8, 2024
f604827
Use ViewOutlineProvider to set sheet shape instead of MaterialShapeDr…
kkafar Jan 9, 2024
087a938
Do not set cornerradius on MaterialShapeDrawable at all
kkafar Jan 9, 2024
d940324
Cleanup attachShapeToScreen a bit
kkafar Jan 9, 2024
1323f1a
Use GradientDrawable to achieve effect of only top corners being rounded
kkafar Jan 9, 2024
52e5839
Stash changes on rounded corners
kkafar Jan 12, 2024
7cab9c2
Restore content diplay
kkafar Feb 11, 2024
1ca4e3d
Callbacks for ime inset, set temporarily push presentation as transpa…
kkafar Feb 12, 2024
49caf0a
Improve sheet animation
kkafar Feb 12, 2024
ab835b8
Restore pre Android 30 keyboard behaviour
kkafar Feb 13, 2024
77b9670
Update example in TE
kkafar Feb 13, 2024
f8b3946
Merge branch 'main' into @kkafar/android-modal-refactor-4
kkafar Feb 13, 2024
4479c1a
Remove merge artifact: index.native.tsx
kkafar Feb 13, 2024
72b2631
Update yarn.lock
kkafar Feb 13, 2024
1acbdc6
Update default values for sheet props
kkafar Feb 13, 2024
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
2 changes: 1 addition & 1 deletion TestsExample/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ import Test2008 from './src/Test2008';
enableFreeze(true);

export default function App() {
return <Test42 />;
return <Test1649 />;
}
2 changes: 2 additions & 0 deletions TestsExample/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ dependencies {
} else {
implementation jscFlavor
}

implementation("com.google.android.material:material:1.9.0")
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
3 changes: 1 addition & 2 deletions TestsExample/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
</style>

</resources>
164 changes: 121 additions & 43 deletions TestsExample/src/Test1649.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { Button, StyleSheet, View, Text, ScrollView } from 'react-native';
import { TouchableOpacity, GestureHandlerRootView, Gesture, TextInput } from 'react-native-gesture-handler';
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
import {
createNativeStackNavigator,
Expand All @@ -13,48 +14,62 @@ const Stack = createNativeStackNavigator();
export default function App(): JSX.Element {
const initialScreenOptions: NativeStackNavigationOptions = {
stackPresentation: 'formSheet',
sheetAllowedDetents: 'all',
sheetLargestUndimmedDetent: 'medium',
sheetAllowedDetents: [0.45, 0.86],
sheetLargestUndimmedDetent: 0,
sheetGrabberVisible: false,
sheetCornerRadius: -1,
sheetExpandsWhenScrolledToEdge: true,
sheetCornerRadius: 20,
sheetExpandsWhenScrolledToEdge: false,
};

return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
// headerRight: () => <View style={styles.headerView} />,
headerTitleStyle: {
color: 'cyan',
},
headerShown: true,
headerHideBackButton: false,
}}>
<Stack.Screen name="First" component={First} />
<Stack.Screen
name="Second"
component={Second}
options={{
fullScreenSwipeEnabled: true,
}}
/>
<Stack.Screen
name="SheetScreen"
component={SheetScreen}
options={{
...initialScreenOptions,
}}
/>
<Stack.Screen
name="SheetScreenWithScrollView"
component={SheetScreenWithScrollView}
options={{
...initialScreenOptions,
}}
/>
</Stack.Navigator>
</NavigationContainer>
<GestureHandlerRootView style={{ flex: 1 }}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
// headerRight: () => <View style={styles.headerView} />,
headerTitleStyle: {
color: 'cyan',
},
headerShown: true,
headerHideBackButton: false,
}}>
<Stack.Screen name="First" component={First} />
<Stack.Screen
name="Second"
component={Second}
options={{
// stackPresentation: 'modal',
fullScreenSwipeEnabled: true,
}}
/>
<Stack.Screen
name="SheetScreen"
component={SheetScreen}
options={{
// stackAnimation: 'slide_from_bottom',
stackAnimation: 'none',
stackPresentation: 'formSheet',
...initialScreenOptions,
}}
/>
<Stack.Screen
name="SheetScreenWithScrollView"
component={SheetScreenWithScrollView}
options={{
...initialScreenOptions,
}}
/>
<Stack.Screen
name="Third"
component={Third}
options={{
// stackPresentation: 'modal',
fullScreenSwipeEnabled: true,
}}
/>
</Stack.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
);
}

Expand All @@ -76,8 +91,13 @@ function Second({
}: {
navigation: NativeStackNavigationProp<ParamListBase>;
}) {
const navigateToFirstCallback = () => {
console.log('Navigate to first callback called');
navigation.navigate('First');
};

return (
<>
<View style={{backgroundColor: 'orchid', flex: 1}}>
<Button
title="Open the sheet"
onPress={() => navigation.navigate('SheetScreen')}
Expand All @@ -86,7 +106,43 @@ function Second({
title="Open the sheet with ScrollView"
onPress={() => navigation.navigate('SheetScreenWithScrollView')}
/>
</>
<Button
title="Go back to first screen"
onPress={navigateToFirstCallback}
/>
<TouchableOpacity onPress={() => console.log('GH Button clicked')}>
<Text>GH BUTTON</Text>
</TouchableOpacity>
</View>
);
}

function Third({
navigation,
}: {
navigation: NativeStackNavigationProp<ParamListBase>;
}) {
const navigateToSecondCallback = () => {
console.log('Navigate Back');
navigation.goBack();
navigation.navigate('Second');
};

return (
<View>
<Button
title="Open the sheet"
onPress={() => navigation.navigate('SheetScreen')}
/>
<Button
title="Open the sheet with ScrollView"
onPress={() => navigation.navigate('SheetScreenWithScrollView')}
/>
<Button
title="Go back to second screen"
onPress={navigateToSecondCallback}
/>
</View>
);
}

Expand Down Expand Up @@ -116,8 +172,20 @@ function SheetScreen({
}
}

const ref = React.useRef(null);

return (
<View style={styles.centeredView}>
<View style={[styles.containerView, { backgroundColor: 'firebrick' }]}>
<TextInput
style={{
backgroundColor: 'lightblue',
paddingHorizontal: 5,
margin: 5,
borderRadius: 5,
}}
value={'hello'}
ref={ref}
/>
<Button
title="Tap me for the first screen"
onPress={() => navigation.navigate('First')}
Expand All @@ -126,6 +194,13 @@ function SheetScreen({
title="Tap me for the second screen"
onPress={() => navigation.navigate('Second')}
/>
<Button
title="Tap me for the third screen / blur"
onPress={() => {
// navigation.goBack();
navigation.navigate('Third');
}}
/>
<Button
title="Change the corner radius"
onPress={() => {
Expand Down Expand Up @@ -192,7 +267,7 @@ function SheetScreenWithScrollView({
return (
<>
<View style={styles.centeredView}>
<ScrollView>
<ScrollView nestedScrollEnabled={true}>
<SheetScreen navigation={navigation} />
{[...Array(40).keys()].map(val => (
<Text key={`${val}`}>Some component {val}</Text>
Expand All @@ -207,7 +282,10 @@ const styles = StyleSheet.create({
headerView: {
height: 20,
width: 20,
backgroundColor: 'red',
// backgroundColor: 'red',
},
containerView: {
flex: 1,
},
centeredView: {
justifyContent: 'center',
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ repositories {

dependencies {
implementation 'com.facebook.react:react-native:+'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'androidx.fragment:fragment:1.3.6'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.fragment:fragment-ktx:1.6.1'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.android.material:material:1.9.0'
Expand Down
Loading
Loading