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

[Sheets] [Pt. 13] Keyboard handling #5586

Merged
merged 73 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
5a98ea6
Include ghost hook to statically export fonts (#5553)
estrattonbailey Oct 1, 2024
801cb62
close all dialogs
haileyok Oct 1, 2024
a17892d
remove a bunch of to-be-useless stuff
haileyok Oct 1, 2024
3971254
remove `Dialog.Handle` uses
haileyok Oct 1, 2024
64f849b
rm handle component
haileyok Oct 1, 2024
6dec099
type
haileyok Oct 1, 2024
d0149a9
get scrollview working
haileyok Oct 1, 2024
40030ba
tidy
haileyok Oct 1, 2024
0b55acd
bump
haileyok Oct 1, 2024
368a9df
bump gesture handler
haileyok Oct 1, 2024
a4c7e2f
tweak types
haileyok Oct 1, 2024
e1ccacc
add props back
haileyok Oct 1, 2024
b900ac6
update types
haileyok Oct 2, 2024
baf1923
update other dialog views
haileyok Oct 2, 2024
a3737f0
replace all buttons with `BottomSheetButton`
haileyok Oct 2, 2024
e2f8e7c
fix type
haileyok Oct 2, 2024
81906df
wizard remove buttons
haileyok Oct 2, 2024
cdfdf49
fix
haileyok Oct 2, 2024
8bd6b2d
fix embed consent
haileyok Oct 2, 2024
65bfd89
buttons in account switcher
haileyok Oct 2, 2024
87c83dd
custom bottom sheet link
haileyok Oct 2, 2024
5a60190
nesting support
haileyok Oct 2, 2024
f251a43
Add intent/verify-email to go server (#5554)
estrattonbailey Oct 2, 2024
3569873
Tweak verify email dialog (#5555)
estrattonbailey Oct 2, 2024
1a7885b
Add suspense boundary in onboarding (#5556)
estrattonbailey Oct 2, 2024
d4b8401
android support
haileyok Oct 2, 2024
1ca6d36
fix type
haileyok Oct 2, 2024
a444fc5
import order (#5571)
haileyok Oct 2, 2024
3972d3d
Ignore built files (#5572)
estrattonbailey Oct 2, 2024
4059668
Make reply prompt more subtle on desktop (#5569)
mozzius Oct 2, 2024
b5a5113
simplify pressable changes
haileyok Oct 2, 2024
349b8b7
rm
haileyok Oct 2, 2024
1ea82c3
rename for clairity
haileyok Oct 2, 2024
f558eb6
fix other buttons in dialogs
haileyok Oct 2, 2024
f365ae0
tweak
haileyok Oct 2, 2024
ca0888c
more fixes
haileyok Oct 2, 2024
43eb47f
Merge remote-tracking branch 'origin/main' into hailey/dialogs-pt10
haileyok Oct 2, 2024
13c9c79
move files around (#5576)
mozzius Oct 2, 2024
c2dac85
Delete messages NUX (#5574)
mozzius Oct 2, 2024
1357ac3
bump
haileyok Oct 2, 2024
3fabcc2
revert some changes
haileyok Oct 2, 2024
1ad73e1
Merge remote-tracking branch 'origin/hailey/dialogs-pt1' into hailey/…
haileyok Oct 2, 2024
b0c0aee
custom bottom sheet link
haileyok Oct 2, 2024
84d32e3
simplify pressable changes
haileyok Oct 2, 2024
5fe4ee9
rm
haileyok Oct 2, 2024
839d6dc
rename for clairity
haileyok Oct 2, 2024
1d5a3ef
tweak
haileyok Oct 2, 2024
6d7b54c
fix namE
haileyok Oct 2, 2024
10cb87b
use context to pick default pressable component
haileyok Oct 2, 2024
431f1ff
adjust
haileyok Oct 2, 2024
fee2468
Merge branch 'hailey/dialogs-pt7-rework' into hailey/dialogs-pt8
haileyok Oct 2, 2024
bb33aa0
revert all the button import changes
haileyok Oct 3, 2024
67e4d77
revert all the changes that are not needed'
haileyok Oct 3, 2024
7ef51ac
Merge branch 'hailey/dialogs-pt8' into hailey/dialogs-pt9
haileyok Oct 3, 2024
1bda59c
Merge branch 'hailey/dialogs-pt9' into hailey/dialogs-pt10
haileyok Oct 3, 2024
5c36d8c
remove unused type
haileyok Oct 3, 2024
24bebec
Merge remote-tracking branch 'origin/main' into hailey/dialogs-pt10
haileyok Oct 3, 2024
d007151
move into repo
haileyok Oct 3, 2024
2ac8308
lint
haileyok Oct 3, 2024
52532fb
add config
haileyok Oct 3, 2024
2b98055
update type imports
haileyok Oct 3, 2024
7ee865f
fix import
haileyok Oct 3, 2024
7489a70
add event to ios
haileyok Oct 3, 2024
0ce5d44
simplify logic
haileyok Oct 3, 2024
b6adc93
ensure event fires on open
haileyok Oct 3, 2024
086dde7
log
haileyok Oct 3, 2024
83d1c38
Allow default PressableComponent override
estrattonbailey Oct 3, 2024
639a7ea
fix accessibility
haileyok Oct 3, 2024
8295c23
before spread
haileyok Oct 3, 2024
b64a294
clean
haileyok Oct 3, 2024
97c5053
implement keyboard handling
haileyok Oct 3, 2024
1c14991
rm now useless components
haileyok Oct 3, 2024
c6d7a5f
Merge remote-tracking branch 'origin/hailey/dialogs-pt1' into hailey/…
haileyok Oct 3, 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
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ android
ios
src/locale/locales
lib/react-compiler-runtime
bskyweb/static
coverage
web-build
1 change: 1 addition & 0 deletions bskyweb/cmd/bskyweb/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func serve(cctx *cli.Context) error {
e.GET("/support/community-guidelines", server.WebGeneric)
e.GET("/support/copyright", server.WebGeneric)
e.GET("/intent/compose", server.WebGeneric)
e.GET("/intent/verify-email", server.WebGeneric)
e.GET("/messages", server.WebGeneric)
e.GET("/messages/:conversation", server.WebGeneric)

Expand Down
56 changes: 56 additions & 0 deletions modules/bottom-sheet/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apply plugin: 'com.android.library'

group = 'expo.modules.bottomsheet'
version = '0.1.0'

def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
apply from: expoModulesCorePlugin
applyKotlinExpoModulesCorePlugin()
useCoreDependencies()
useExpoPublishing()

// If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
// The Android SDK versions will be bumped from time to time in SDK releases and may introduce breaking changes in your module code.
// Most of the time, you may like to manage the Android SDK versions yourself.
def useManagedAndroidSdkVersions = false
if (useManagedAndroidSdkVersions) {
useDefaultAndroidSdkVersions()
} else {
buildscript {
// Simple helper that allows the root project to override versions declared by this library.
ext.safeExtGet = { prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
}
project.android {
compileSdkVersion safeExtGet("compileSdkVersion", 34)
defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 21)
targetSdkVersion safeExtGet("targetSdkVersion", 34)
}
}
}

android {
namespace "expo.modules.bottomsheet"
defaultConfig {
versionCode 1
versionName "0.1.0"
}
lintOptions {
abortOnError false
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.8"
}
}

dependencies {
implementation project(':expo-modules-core')
implementation "androidx.compose.material3:material3:1.3.0"
implementation "androidx.compose.material:material:1.7.2"
implementation "com.facebook.react:react-native:+"
}
2 changes: 2 additions & 0 deletions modules/bottom-sheet/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package expo.modules.bottomsheet

import android.content.Context
import android.view.View
import android.widget.FrameLayout
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.platform.ComposeView
import androidx.core.view.allViews
import com.facebook.react.ReactRootView
import expo.modules.kotlin.AppContext
import expo.modules.kotlin.viewevent.EventDispatcher
import expo.modules.kotlin.views.ExpoView

class BottomSheetView(
context: Context,
appContext: AppContext,
) : ExpoView(context, appContext) {
val sheetState = mutableStateOf(SheetState())

private var reactRootView: ReactRootView? = null
private var innerView: View? = null

private var sheetView: ComposeView? = null

private val onStateChange by EventDispatcher()
private val onAttemptDismiss by EventDispatcher()

// Props
var preventDismiss = false
var minHeight = 0f
var maxHeight = 0f

private var isOpen: Boolean = false
set(value) {
if (field == value) return

field = value
this.sheetState.value.isOpen = value
onStateChange(
mapOf(
"state" to if (value) "open" else "closed",
),
)
}

private var isOpening: Boolean = false
set(value) {
field = value
if (value) {
onStateChange(mapOf("state" to "opening"))
}
}

private var isClosing: Boolean = false
set(value) {
field = value
if (value) {
onStateChange(mapOf("state" to "closing"))
}
}

private var hasInitiallyOpened = false

// Lifecycle

override fun addView(
child: View?,
index: Int,
) {
this.innerView = child
}

override fun onLayout(
changed: Boolean,
l: Int,
t: Int,
r: Int,
b: Int,
) {
this.innerView?.let {
val height =
it.allViews
.last()
.measuredHeight
.toFloat()
this.present(height)
}
}

private fun destroy() {
this.isClosing = false
this.isOpen = false

this.getRootLayout().removeView(this.sheetView)
this.sheetView = null

this.reactRootView = null
this.innerView = null
}

// Presentation

private fun present(contentHeight: Float) {
val innerView = this.innerView ?: return

// For GestureRootView to work, we need to create a ReactRootView for the innerView to be
// contained inside of
val reactRootView = ReactRootView(context)
reactRootView.addView(innerView)
this.reactRootView = reactRootView

this.isOpening = true
this.sheetView =
ComposeView(context).also {
it.setContent {
SheetView(
state = sheetState,
innerView = reactRootView,
contentHeight = innerView.height.toFloat(),
onDismissRequest = {
onAttemptDismiss(mapOf())
if (!preventDismiss) {
dismiss()
}
},
onExpanded = {
isOpening = false
isOpen = true
hasInitiallyOpened = true
},
onHidden = {
if (hasInitiallyOpened) {
destroy()
}
},
)
}
getRootLayout().addView(it)
}
}

fun dismiss() {
this.isClosing = true
this.destroy()
}

// Utils

private fun getRootLayout(): FrameLayout = appContext.currentActivity!!.findViewById(android.R.id.content)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package expo.modules.bottomsheet

import android.graphics.Color
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition

class BottomSheetModule : Module() {
override fun definition() =
ModuleDefinition {
Name("BlueskyBottomSheet")

Function("getSafeAreaInset") {
return@Function 10 // @TODO
}

View(BottomSheetView::class) {
Events(
arrayOf(
"onStateChange",
"onAttemptDismiss",
),
)

AsyncFunction("dismiss") { view: BottomSheetView ->
view.dismiss()
}

Prop("preventDismiss") { view: BottomSheetView, prop: Boolean ->
view.preventDismiss = prop
}

Prop("minHeight") { view: BottomSheetView, prop: Float ->
view.minHeight = prop
}

Prop("maxHeight") { view: BottomSheetView, prop: Float ->
view.maxHeight = prop
}

Prop("cornerRadius") { view: BottomSheetView, prop: Float ->
view.sheetState.value.cornerRadius = prop
}

Prop("containerBackgroundColor") { view: BottomSheetView, prop: String ->
view.sheetState.value.containerBackgroundColor = Color.parseColor(prop)
}

Prop("preventExpansion") { view: BottomSheetView, prop: Boolean ->
view.sheetState.value.preventExpansion = prop
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package expo.modules.bottomsheet

import android.view.View
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SheetValue
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView

data class SheetState(
var isOpen: Boolean = false,
var cornerRadius: Float? = null,
var containerBackgroundColor: Int? = null,
var preventExpansion: Boolean = false,
)

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SheetView(
state: MutableState<SheetState>,
innerView: View,
contentHeight: Float,
onDismissRequest: () -> Unit,
onExpanded: () -> Unit,
onHidden: () -> Unit,
) {
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = false)

ModalBottomSheet(
sheetState = sheetState,
onDismissRequest = onDismissRequest,
shape =
RoundedCornerShape(
topStart = state.value.cornerRadius ?: 0f,
topEnd = state.value.cornerRadius ?: 0f,
),
containerColor = Color(state.value.containerBackgroundColor ?: android.graphics.Color.TRANSPARENT),
) {
Column(
Modifier
.fillMaxWidth()
.height(contentHeight.dp)
// Prevent covering up the handle
.padding(top = 34.dp),
) {
AndroidView(
factory = { innerView },
)
}
}

LaunchedEffect(sheetState.currentValue) {
if (sheetState.currentValue == SheetValue.PartiallyExpanded || sheetState.currentValue == SheetValue.Expanded) {
onExpanded()
} else if (sheetState.currentValue == SheetValue.Hidden) {
onHidden()
}
}
}
9 changes: 9 additions & 0 deletions modules/bottom-sheet/expo-module.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"platforms": ["ios", "android"],
"ios": {
"modules": ["BottomSheetModule"]
},
"android": {
"modules": ["expo.modules.bottomsheet.BottomSheetModule"]
}
}
13 changes: 13 additions & 0 deletions modules/bottom-sheet/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
BottomSheetSnapPoint,
BottomSheetState,
BottomSheetViewProps,
} from './src/BottomSheet.types'
import {BottomSheetView} from './src/BottomSheetView'

export {
BottomSheetSnapPoint,
type BottomSheetState,
BottomSheetView,
type BottomSheetViewProps,
}
21 changes: 21 additions & 0 deletions modules/bottom-sheet/ios/BottomSheet.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Pod::Spec.new do |s|
s.name = 'BottomSheet'
s.version = '1.0.0'
s.summary = 'A bottom sheet for use in Bluesky'
s.description = 'A bottom sheet for use in Bluesky'
s.author = ''
s.homepage = 'https://github.com/bluesky-social/social-app'
s.platforms = { :ios => '15.0', :tvos => '15.0' }
s.source = { git: '' }
s.static_framework = true

s.dependency 'ExpoModulesCore'

# Swift/Objective-C compatibility
s.pod_target_xcconfig = {
'DEFINES_MODULE' => 'YES',
'SWIFT_COMPILATION_MODE' => 'wholemodule'
}

s.source_files = "**/*.{h,m,swift}"
end
Loading
Loading