Skip to content

Commit e8733bc

Browse files
authored
Merge pull request #345 from obytes/keyboard-handling
Keyboard handling
2 parents 6450346 + 87f155c commit e8733bc

25 files changed

+968
-736
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('react-native-keyboard-controller/jest');

android/app/build.gradle

+31-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ apply plugin: "com.facebook.react"
44

55
def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()
66

7+
static def versionToNumber(major, minor, patch) {
8+
return patch * 100 + minor * 10000 + major * 1000000
9+
}
10+
11+
def getRNVersion() {
12+
def version = providers.exec {
13+
workingDir(projectDir)
14+
commandLine("node", "-e", "console.log(require('react-native/package.json').version);")
15+
}.standardOutput.asText.get().trim()
16+
17+
def coreVersion = version.split("-")[0]
18+
def (major, minor, patch) = coreVersion.tokenize('.').collect { it.toInteger() }
19+
20+
return versionToNumber(
21+
major,
22+
minor,
23+
patch
24+
)
25+
}
26+
def rnVersion = getRNVersion()
27+
728
/**
829
* This is the configuration block to customize your React Native Android app.
930
* By default you don't need to apply any configuration, just uncomment the lines you need.
@@ -57,6 +78,11 @@ react {
5778
//
5879
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
5980
// hermesFlags = ["-O", "-output-source-map"]
81+
82+
if (rnVersion >= versionToNumber(0, 75, 0)) {
83+
/* Autolinking */
84+
autolinkLibrariesWithApp()
85+
}
6086
}
6187

6288
/**
@@ -110,6 +136,7 @@ android {
110136
shrinkResources (findProperty('android.enableShrinkResourcesInReleaseBuilds')?.toBoolean() ?: false)
111137
minifyEnabled enableProguardInReleaseBuilds
112138
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
139+
crunchPngs (findProperty('android.enablePngCrunchInReleaseBuilds')?.toBoolean() ?: true)
113140
}
114141
}
115142
packagingOptions {
@@ -168,5 +195,7 @@ dependencies {
168195
}
169196
}
170197

171-
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
172-
applyNativeModulesAppBuildGradle(project)
198+
if (rnVersion < versionToNumber(0, 75, 0)) {
199+
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
200+
applyNativeModulesAppBuildGradle(project)
201+
}

android/app/src/main/res/values/styles.xml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<item name="android:editTextStyle">@style/ResetEditText</item>
55
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
66
<item name="colorPrimary">@color/colorPrimary</item>
7-
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
87
<item name="android:statusBarColor">#2E3C4B</item>
98
</style>
109
<style name="ResetEditText" parent="@android:style/Widget.EditText">

android/gradle.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ android.useAndroidX=true
2525
# Automatically convert third-party libraries to use AndroidX
2626
android.enableJetifier=true
2727

28+
# Enable AAPT2 PNG crunching
29+
android.enablePngCrunchInReleaseBuilds=true
30+
2831
# Use this property to specify which architecture you want to build.
2932
# You can also override it from the CLI using
3033
# ./gradlew <task> -PreactNativeArchitectures=x86_64
@@ -54,6 +57,3 @@ EX_DEV_CLIENT_NETWORK_INSPECTOR=true
5457

5558
# Use legacy packaging to compress native libraries in the resulting APK.
5659
expo.useLegacyPackaging=false
57-
58-
android.kotlinVersion=1.7.22
59-
android.extraMavenRepos=[]
-9 Bytes
Binary file not shown.

android/gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
plugins {
4+
kotlin("jvm") version "1.9.24"
5+
id("java-gradle-plugin")
6+
}
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
gradlePlugin {
13+
plugins {
14+
create("reactSettingsPlugin") {
15+
id = "com.facebook.react.settings"
16+
implementationClass = "expo.plugins.ReactSettingsPlugin"
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package expo.plugins
2+
3+
import org.gradle.api.Plugin
4+
import org.gradle.api.initialization.Settings
5+
6+
class ReactSettingsPlugin : Plugin<Settings> {
7+
override fun apply(settings: Settings) {
8+
// Do nothing, just register the plugin.
9+
}
10+
}

android/settings.gradle

+50-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
1+
pluginManagement {
2+
def version = providers.exec {
3+
commandLine("node", "-e", "console.log(require('react-native/package.json').version);")
4+
}.standardOutput.asText.get().trim()
5+
def (_, reactNativeMinor, reactNativePatch) = version.split("-")[0].tokenize('.').collect { it.toInteger() }
6+
7+
includeBuild(new File(["node", "--print", "require.resolve('@react-native/gradle-plugin/package.json')"].execute(null, rootDir).text.trim()).getParentFile().toString())
8+
if(reactNativeMinor == 74 && reactNativePatch <= 3){
9+
includeBuild("react-settings-plugin")
10+
}
11+
}
12+
13+
plugins { id("com.facebook.react.settings") }
14+
15+
def getRNMinorVersion() {
16+
def version = providers.exec {
17+
commandLine("node", "-e", "console.log(require('react-native/package.json').version);")
18+
}.standardOutput.asText.get().trim()
19+
20+
def coreVersion = version.split("-")[0]
21+
def (major, minor, patch) = coreVersion.tokenize('.').collect { it.toInteger() }
22+
23+
return minor
24+
}
25+
26+
if (getRNMinorVersion() >= 75) {
27+
extensions.configure(com.facebook.react.ReactSettingsExtension) { ex ->
28+
if (System.getenv('EXPO_UNSTABLE_CORE_AUTOLINKING') == '1') {
29+
println('\u001B[32mUsing expo-modules-autolinking as core autolinking source\u001B[0m')
30+
def command = [
31+
'node',
32+
'--no-warnings',
33+
'--eval',
34+
'require(require.resolve(\'expo-modules-autolinking\', { paths: [require.resolve(\'expo/package.json\')] }))(process.argv.slice(1))',
35+
'react-native-config',
36+
'--json',
37+
'--platform',
38+
'android'
39+
].toList()
40+
ex.autolinkLibrariesFromCommand(command)
41+
} else {
42+
ex.autolinkLibrariesFromCommand()
43+
}
44+
}
45+
}
46+
147
rootProject.name = 'ObytesApp'
248

349
dependencyResolutionManagement {
@@ -11,8 +57,10 @@ dependencyResolutionManagement {
1157
apply from: new File(["node", "--print", "require.resolve('expo/package.json')"].execute(null, rootDir).text.trim(), "../scripts/autolinking.gradle");
1258
useExpoModules()
1359

14-
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
15-
applyNativeModulesSettingsGradle(settings)
60+
if (getRNMinorVersion() < 75) {
61+
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
62+
applyNativeModulesSettingsGradle(settings)
63+
}
1664

1765
include ':app'
1866
includeBuild(new File(["node", "--print", "require.resolve('@react-native/gradle-plugin/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile())

app.config.ts

-8
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
5050
],
5151
'expo-localization',
5252
'expo-router',
53-
[
54-
'expo-build-properties',
55-
{
56-
android: {
57-
kotlinVersion: '1.7.22', // this is for softinput package
58-
},
59-
},
60-
],
6153
[
6254
'app-icon-badge',
6355
{

docs/src/content/docs/ui-and-theme/Forms.mdx

+9-14
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,14 @@ Any Component with props that inherit from the `InputControllerType` can be used
106106

107107
## Handling Keyboard
108108

109-
The template comes with [`react-native-avoid-softinput`](https://mateusz1913.github.io/react-native-avoid-softinput/) pre-installed and configured to handle the keyboard. You only need to use the `useSoftKeyboardEffect` hook on your screen, and you're good to go.
109+
The template comes with [`react-native-keyboard-controller`](https://kirillzyusko.github.io/react-native-keyboard-controller/) pre-installed and configured to handle the keyboard. You only need to check the [documentation](https://kirillzyusko.github.io/react-native-keyboard-controller/) and use the appropriate approach for your use case. ( note that we already added the `KeyboardProvider` to the layout in the root file)
110110

111-
```tsx
112-
import React from 'react';
113-
import { useSoftKeyboardEffect } from '@/core/keyboard';
114-
import { LoginForm } from './login-form';
115-
116-
export const Login = () => {
117-
useSoftKeyboardEffect();
118-
return <LoginForm />;
119-
};
120-
```
111+
Make sure to check the following video for more details on how to handle keyboard in react native:
121112

122-
:::tip
123-
Note that the hook is not an all-in-one solution for all cases, and you might need more customization depending on your use case. So, please refer to the documentation [recipes pages](https://mateusz1913.github.io/react-native-avoid-softinput/docs/recipes/recipes-form) for more information.
124-
:::
113+
<div class="embed-container">
114+
<iframe
115+
src="https://www.youtube.com/embed/Y51mDfAhd4E?si=8uPml61z0R1hsZGy&amp;start=1139"
116+
frameborder="0"
117+
allowfullscreen
118+
></iframe>
119+
</div>

docs/src/styles/custom.css

+17
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,20 @@
8080
font-weight: 600;
8181
line-height: 1.2;
8282
}
83+
84+
.embed-container {
85+
position: relative;
86+
padding-bottom: 56.25%;
87+
height: 0;
88+
overflow: hidden;
89+
max-width: 100%;
90+
}
91+
.embed-container iframe,
92+
.embed-container object,
93+
.embed-container embed {
94+
position: absolute;
95+
top: 0;
96+
left: 0;
97+
width: 100%;
98+
height: 100%;
99+
}

0 commit comments

Comments
 (0)