Fix 3dot menu bug

This commit is contained in:
2026-09-08 11:40:39 -04:00
parent f389e626ea
commit 4b87538410
3 changed files with 94 additions and 20 deletions
@@ -551,8 +551,11 @@ fun MainScreen(
var showScriptDialog by remember { mutableStateOf(false) } var showScriptDialog by remember { mutableStateOf(false) }
var showPrinterSessionDialog by remember { mutableStateOf(false) } var showPrinterSessionDialog by remember { mutableStateOf(false) }
var terminalInputViewRef by remember { mutableStateOf<TerminalInputView?>(null) }
LaunchedEffect(isFindDialogOpen) { LaunchedEffect(isFindDialogOpen) {
if (isFindDialogOpen) { if (isFindDialogOpen) {
terminalInputViewRef?.hideSoftKeyboard()
showFindDialog = true showFindDialog = true
onSetFindDialogOpen(false) onSetFindDialogOpen(false)
} }
@@ -560,13 +563,12 @@ fun MainScreen(
LaunchedEffect(isFtDialogOpen) { LaunchedEffect(isFtDialogOpen) {
if (isFtDialogOpen) { if (isFtDialogOpen) {
terminalInputViewRef?.hideSoftKeyboard()
showFtDialog = true showFtDialog = true
onSetFtDialogOpen(false) onSetFtDialogOpen(false)
} }
} }
var terminalInputViewRef by remember { mutableStateOf<TerminalInputView?>(null) }
val lifecycleOwner = LocalLifecycleOwner.current val lifecycleOwner = LocalLifecycleOwner.current
DisposableEffect(lifecycleOwner) { DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { _, event -> val observer = LifecycleEventObserver { _, event ->
@@ -721,14 +723,35 @@ fun MainScreen(
fourColorOverride = fourColorOverride, fourColorOverride = fourColorOverride,
hapticFeedbackEnabled = hapticFeedback, hapticFeedbackEnabled = hapticFeedback,
onClearShift = onClearShift, onClearShift = onClearShift,
onConnectClick = { showConnectDialog = true }, onConnectClick = {
terminalInputViewRef?.hideSoftKeyboard()
showConnectDialog = true
},
onDisconnectClick = { viewModel.disconnect() }, onDisconnectClick = { viewModel.disconnect() },
onFtClick = { showFtDialog = true }, onFtClick = {
onFieldInspectorClick = { showFieldInspectorDialog = true }, terminalInputViewRef?.hideSoftKeyboard()
onFindClick = { showFindDialog = true }, showFtDialog = true
onScreenExportClick = { showScreenExportDialog = true }, },
onScriptClick = { showScriptDialog = true }, onFieldInspectorClick = {
onPrinterSessionClick = { showPrinterSessionDialog = true }, terminalInputViewRef?.hideSoftKeyboard()
showFieldInspectorDialog = true
},
onFindClick = {
terminalInputViewRef?.hideSoftKeyboard()
showFindDialog = true
},
onScreenExportClick = {
terminalInputViewRef?.hideSoftKeyboard()
showScreenExportDialog = true
},
onScriptClick = {
terminalInputViewRef?.hideSoftKeyboard()
showScriptDialog = true
},
onPrinterSessionClick = {
terminalInputViewRef?.hideSoftKeyboard()
showPrinterSessionDialog = true
},
onToggleLightPen = { viewModel.toggleLightPen() }, onToggleLightPen = { viewModel.toggleLightPen() },
onToggleDocMode = { viewModel.toggleDocMode() }, onToggleDocMode = { viewModel.toggleDocMode() },
onToggleWordWrap = { viewModel.toggleWordWrap() }, onToggleWordWrap = { viewModel.toggleWordWrap() },
@@ -739,7 +762,10 @@ fun MainScreen(
viewModel.setFourColorOverride(next) viewModel.setFourColorOverride(next)
AppSettings.setFourColorOverride(context, next) AppSettings.setFourColorOverride(context, next)
}, },
onSettingsClick = { showSettingsDialog = true }, onSettingsClick = {
terminalInputViewRef?.hideSoftKeyboard()
showSettingsDialog = true
},
onSendAid = { aid -> onSendAid = { aid ->
viewModel.sendAid(aid) viewModel.sendAid(aid)
terminalInputViewRef?.showSoftKeyboard() terminalInputViewRef?.showSoftKeyboard()
@@ -825,7 +851,10 @@ fun MainScreen(
if (showConnectDialog) { if (showConnectDialog) {
ConnectDialog( ConnectDialog(
onDismiss = { showConnectDialog = false }, onDismiss = {
showConnectDialog = false
terminalInputViewRef?.showSoftKeyboard()
},
onConnect = { host, port, model, dynamicRows, dynamicCols, luName, hostType, useTls, tlsVerifyCert, tn3270e, graphicsMode, cp, pType, pHost, pPort, pUser, pPass -> onConnect = { host, port, model, dynamicRows, dynamicCols, luName, hostType, useTls, tlsVerifyCert, tn3270e, graphicsMode, cp, pType, pHost, pPort, pUser, pPass ->
showConnectDialog = false showConnectDialog = false
viewModel.connect(host, port, model, dynamicRows, dynamicCols, luName, hostType, useTls, tlsVerifyCert, tn3270e, graphicsMode, cp, pType, pHost, pPort, pUser, pPass) viewModel.connect(host, port, model, dynamicRows, dynamicCols, luName, hostType, useTls, tlsVerifyCert, tn3270e, graphicsMode, cp, pType, pHost, pPort, pUser, pPass)
@@ -839,7 +868,10 @@ fun MainScreen(
initialHostType = viewModel.activeHostType, initialHostType = viewModel.activeHostType,
ftProgressState = ftState, ftProgressState = ftState,
client = viewModel.getClient(), client = viewModel.getClient(),
onDismiss = { showFtDialog = false }, onDismiss = {
showFtDialog = false
terminalInputViewRef?.showSoftKeyboard()
},
onStartTransfer = { config -> onStartTransfer = { config ->
viewModel.startFileTransfer(config) { error -> viewModel.startFileTransfer(config) { error ->
if (error != null) { if (error != null) {
@@ -879,7 +911,10 @@ fun MainScreen(
initialFourColorOverride = fourColorOverride, initialFourColorOverride = fourColorOverride,
initialNumericFieldLock = AppSettings.getNumericFieldLock(context), initialNumericFieldLock = AppSettings.getNumericFieldLock(context),
initialAutoSkipEnabled = AppSettings.getAutoSkipEnabled(context), initialAutoSkipEnabled = AppSettings.getAutoSkipEnabled(context),
onDismiss = { showSettingsDialog = false }, onDismiss = {
showSettingsDialog = false
terminalInputViewRef?.showSoftKeyboard()
},
onSave = { mask, blink, haptic, verify, gfx, defaultCp, theme, crosshair, style, blockSel, startup, dynRows, dynCols, onSave = { mask, blink, haptic, verify, gfx, defaultCp, theme, crosshair, style, blockSel, startup, dynRows, dynCols,
doc, wrap, startCol, endCol, bell, bellCol, tabs, resetIns, fourCol, numLk, autoSk -> doc, wrap, startCol, endCol, bell, bellCol, tabs, resetIns, fourCol, numLk, autoSk ->
showSettingsDialog = false showSettingsDialog = false
@@ -912,7 +947,10 @@ fun MainScreen(
FieldInspectorDialog( FieldInspectorDialog(
client = viewModel.getClient(), client = viewModel.getClient(),
screenVersion = screenVersion, screenVersion = screenVersion,
onDismiss = { showFieldInspectorDialog = false }, onDismiss = {
showFieldInspectorDialog = false
terminalInputViewRef?.showSoftKeyboard()
},
onJumpToField = { addr -> onJumpToField = { addr ->
viewModel.setCursor(addr) viewModel.setCursor(addr)
terminalInputViewRef?.showSoftKeyboard() terminalInputViewRef?.showSoftKeyboard()
@@ -923,7 +961,10 @@ fun MainScreen(
if (showFindDialog) { if (showFindDialog) {
FindDialog( FindDialog(
cols = cols, cols = cols,
onDismiss = { showFindDialog = false }, onDismiss = {
showFindDialog = false
terminalInputViewRef?.showSoftKeyboard()
},
onFind = { query: String, matchCase: Boolean, forward: Boolean -> onFind = { query: String, matchCase: Boolean, forward: Boolean ->
viewModel.find(query, matchCase, forward) viewModel.find(query, matchCase, forward)
}, },
@@ -941,13 +982,19 @@ fun MainScreen(
programSymbolManager = viewModel.getClient()?.programSymbolManager, programSymbolManager = viewModel.getClient()?.programSymbolManager,
graphicsPlane = viewModel.getClient()?.graphicsPlane, graphicsPlane = viewModel.getClient()?.graphicsPlane,
maskHidden = maskHiddenInput, maskHidden = maskHiddenInput,
onDismiss = { showScreenExportDialog = false } onDismiss = {
showScreenExportDialog = false
terminalInputViewRef?.showSoftKeyboard()
}
) )
} }
if (showScriptDialog) { if (showScriptDialog) {
ScriptDialog( ScriptDialog(
onDismiss = { showScriptDialog = false }, onDismiss = {
showScriptDialog = false
terminalInputViewRef?.showSoftKeyboard()
},
onExecuteScript = { script: String, onStatus: (String) -> Unit, onComplete: (String?) -> Unit -> onExecuteScript = { script: String, onStatus: (String) -> Unit, onComplete: (String?) -> Unit ->
viewModel.executeScript(script, onStatus, onComplete) viewModel.executeScript(script, onStatus, onComplete)
} }
@@ -960,7 +1007,10 @@ fun MainScreen(
initialHost = activeHost, initialHost = activeHost,
initialCodePage = codePage, initialCodePage = codePage,
initialUseTls = isTlsActive, initialUseTls = isTlsActive,
onDismiss = { showPrinterSessionDialog = false } onDismiss = {
showPrinterSessionDialog = false
terminalInputViewRef?.showSoftKeyboard()
}
) )
} }
@@ -15,6 +15,8 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.activity.compose.BackHandler
import androidx.compose.ui.window.PopupProperties
import haus.nightmare.lib3270j.ConnectionState import haus.nightmare.lib3270j.ConnectionState
import haus.nightmare.lib3270j.protocol.DS3270Constants.* import haus.nightmare.lib3270j.protocol.DS3270Constants.*
@@ -61,6 +63,11 @@ fun TwoRowKeyBar(
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
var menuExpanded by remember { mutableStateOf(false) } var menuExpanded by remember { mutableStateOf(false) }
var lastDismissTime by remember { mutableLongStateOf(0L) }
BackHandler(enabled = menuExpanded) {
menuExpanded = false
}
Column( Column(
modifier = modifier modifier = modifier
@@ -83,11 +90,22 @@ fun TwoRowKeyBar(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
hapticFeedbackEnabled = hapticFeedbackEnabled, hapticFeedbackEnabled = hapticFeedbackEnabled,
innerPaddingHorizontal = 0.dp, innerPaddingHorizontal = 0.dp,
onClick = { menuExpanded = true } onClick = {
if (System.currentTimeMillis() - lastDismissTime > 200L) {
menuExpanded = !menuExpanded
}
}
) )
DropdownMenu( DropdownMenu(
expanded = menuExpanded, expanded = menuExpanded,
onDismissRequest = { menuExpanded = false }, onDismissRequest = {
menuExpanded = false
lastDismissTime = System.currentTimeMillis()
},
properties = PopupProperties(
focusable = false,
dismissOnClickOutside = true
),
modifier = Modifier modifier = Modifier
.background(Color(0xFF2C2D30)) .background(Color(0xFF2C2D30))
.heightIn(max = 420.dp) .heightIn(max = 420.dp)
@@ -111,4 +111,10 @@ class TerminalInputView(context: Context) : View(context) {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
imm?.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT) imm?.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
} }
fun hideSoftKeyboard() {
clearFocus()
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
imm?.hideSoftInputFromWindow(windowToken, 0)
}
} }