Skip to content

Commit 463fafe

Browse files
authored
Merge pull request #214 from caarmen/more-scrolling
More adjustments related to scrolling...
2 parents cc52c43 + 9e82443 commit 463fafe

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

app/src/main/AndroidManifest.xml

+13
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,24 @@
4646
android:supportsRtl="true"
4747
android:enableOnBackInvokedCallback="true"
4848
android:theme="@style/AppTheme">
49+
<!--
50+
Set windowSoftInputMode=adjustPan.
51+
Without this, we have this problem:
52+
- Have a long poem already entered.
53+
- Launch the app.
54+
- Swipe to the composer tab.
55+
- Scroll to the end of the poem.
56+
- Open the keyboard at the end.
57+
- Type a few lines.
58+
The lines are entered, but the keyboard is still covering them.
59+
You'd have to swipe the view to scroll it up, to reveal the new lines.
60+
-->
4961
<activity
5062
android:name=".main.MainActivity"
5163
android:label="@string/app_name"
5264
android:launchMode="singleTask"
5365
android:theme="@style/AppTheme.NoActionBar"
66+
android:windowSoftInputMode="adjustPan"
5467
android:exported="true">
5568
<intent-filter>
5669
<action android:name="android.intent.action.MAIN" />

app/src/main/kotlin/ca/rmen/android/poetassistant/main/MainActivity.kt

-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import android.view.MenuItem
3939
import android.view.Window
4040
import android.view.WindowManager
4141
import android.view.inputmethod.InputMethodManager
42-
import androidx.activity.OnBackPressedCallback
4342
import androidx.core.view.updatePadding
4443
import androidx.lifecycle.ViewModelProvider
4544
import ca.rmen.android.poetassistant.BuildConfig
@@ -136,15 +135,6 @@ class MainActivity : AppCompatActivity(), OnWordClickListener, WarningNoSpaceDia
136135
top = insets.top,
137136
)
138137
}
139-
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
140-
override fun handleOnBackPressed() {
141-
if (mBinding.appBarLayout.top < 0) {
142-
mBinding.appBarLayout.setExpanded(true, true)
143-
} else {
144-
finish()
145-
}
146-
}
147-
})
148138
val searchView = mBinding.searchView
149139
val suggestionsViewModel = ViewModelProvider(this).get(SuggestionsViewModel::class.java)
150140
mSearch.setSearchView(searchView, suggestionsViewModel)

app/src/main/kotlin/ca/rmen/android/poetassistant/main/reader/ReaderFragment.kt

+12
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ class ReaderFragment : Fragment(), ConfirmDialogFragment.ConfirmDialogListener {
107107
DebounceTextWatcher.debounce(mBinding.tvText) { mViewModel.updateWordCount() }
108108
TextPopupMenu.addSelectionPopupMenu(mBinding.root, mBinding.tvText, activity as OnWordClickListener)
109109
mViewModel.playButtonStateLiveData.observe(this, mPlayButtonStateObserver)
110+
// Add padding to the bottom of the reader content when the keyboard is open.
111+
// Without this, we have this problem:
112+
// 1. Have a long poem already entered.
113+
// 2. Launch the app.
114+
// 3. Swipe to the composer tab.
115+
// 4. Tap in the middle of the poem to open the keyboard.
116+
// You can't scroll down to the end of the poem.
117+
//
118+
// Note this has a little glitch, but maybe pas grave?:
119+
// 4. Tap in the end of the poem (instead of the middle).
120+
// You can scroll down to the end of the poem, and you see quite a bit of
121+
// empty padding underneath it.
110122
ViewCompat.setOnApplyWindowInsetsListener(mBinding.tvText) { _, insets ->
111123
val imeHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom
112124
mBinding.readerContent.updatePadding(

app/src/main/res/layout/fragment_reader.xml

+12-3
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,22 @@
3434
type="ca.rmen.android.poetassistant.main.reader.ReaderFragment.ButtonListener"/>
3535
</data>
3636

37-
<ScrollView
37+
<!--
38+
Use NestedScrollView.
39+
Without this, we have this problem:
40+
- have a long poem already entered.
41+
- launch the app.
42+
- swipe to the composer tab.
43+
- don't open the keyboard (don't tap inside the edit text).
44+
- try to scroll down.
45+
You can't scroll down to the end of the poem
46+
-->
47+
<androidx.core.widget.NestedScrollView
3848
android:layout_width="match_parent"
3949
android:layout_height="match_parent"
4050
android:clipChildren="false"
4151
android:clipToPadding="false"
4252
android:fillViewport="false"
43-
android:nestedScrollingEnabled="true"
4453
android:paddingBottom="@dimen/activity_vertical_margin"
4554
android:paddingLeft="@dimen/activity_horizontal_margin"
4655
android:paddingRight="@dimen/activity_horizontal_margin"
@@ -94,5 +103,5 @@
94103
app:layout_constraintBottom_toBottomOf="parent"
95104
tools:text="45 words, 300 characters"/>
96105
</androidx.constraintlayout.widget.ConstraintLayout>
97-
</ScrollView>
106+
</androidx.core.widget.NestedScrollView>
98107
</layout>

0 commit comments

Comments
 (0)