Skip to content

feat: added typescript support and auto-linking #30

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

251 changes: 144 additions & 107 deletions Examples/KeyboardAdjustExample.android.js
Original file line number Diff line number Diff line change
@@ -1,124 +1,161 @@
'use strict';
"use strict";

var React = require('react-native');
var React = require("react-native");
var {
AppRegistry,
StyleSheet,
Text,
TextInput,
TouchableWithoutFeedback,
View
AppRegistry,
StyleSheet,
Text,
TextInput,
TouchableWithoutFeedback,
View,
} = React;

var dismissKeyboard = require('dismissKeyboard');
var AndroidKeyboardAdjust = require('NativeModules').AndroidKeyboardAdjust;
var dismissKeyboard = require("dismissKeyboard");
var AndroidKeyboardAdjust = require("NativeModules").AndroidKeyboardAdjust;

var KeyboardAdjustExample = React.createClass({
getInitialState: function() {
return {
setting: 'nothing'
};
},
getInitialState: function () {
return {
setting: "nothing",
};
},

setKeyboardSetting: function(setting) {
this.setState({setting: setting});
setKeyboardSetting: function (setting) {
this.setState({ setting: setting });

switch (setting) {
case 'nothing':
AndroidKeyboardAdjust.setAdjustNothing();
break;
case 'pan':
AndroidKeyboardAdjust.setAdjustPan();
break;
case 'resize':
AndroidKeyboardAdjust.setAdjustResize();
break;
case 'unspecified':
AndroidKeyboardAdjust.setAdjustUnspecified();
break;
}
},
switch (setting) {
case "nothing":
AndroidKeyboardAdjust.setAdjustNothing();
break;
case "pan":
AndroidKeyboardAdjust.setAdjustPan();
break;
case "resize":
AndroidKeyboardAdjust.setAdjustResize();
break;
case "unspecified":
AndroidKeyboardAdjust.setAdjustUnspecified();
break;
}
},

render: function() {
return (
<View style={styles.container}>
<View style={styles.settingButtons}>
<TouchableWithoutFeedback onPress={() => this.setKeyboardSetting('nothing')}>
<View style={[styles.settingButton, this.state.setting == 'nothing' ? {backgroundColor: 'green'} : {}]}>
<Text style={styles.settingButtonText}>Adjust Nothing</Text>
</View>
</TouchableWithoutFeedback>
<TouchableWithoutFeedback onPress={() => this.setKeyboardSetting('pan')}>
<View style={[styles.settingButton, this.state.setting == 'pan' ? {backgroundColor: 'green'} : {}]}>
<Text style={styles.settingButtonText}>Adjust Pan</Text>
</View>
</TouchableWithoutFeedback>
</View>
<View style={styles.settingButtons}>
<TouchableWithoutFeedback onPress={() => this.setKeyboardSetting('resize')}>
<View style={[styles.settingButton, this.state.setting == 'resize' ? {backgroundColor: 'green'} : {}]}>
<Text style={styles.settingButtonText}>Adjust Resize</Text>
</View>
</TouchableWithoutFeedback>
<TouchableWithoutFeedback onPress={() => this.setKeyboardSetting('unspecified')}>
<View style={[styles.settingButton, this.state.setting == 'unspecified' ? {backgroundColor: 'green'} : {}]}>
<Text style={styles.settingButtonText}>Adjust Unspecified</Text>
</View>
</TouchableWithoutFeedback>
</View>
<View style={styles.settingButtons}>
<TouchableWithoutFeedback onPress={() => dismissKeyboard()}>
<View style={styles.settingButton}>
<Text style={styles.settingButtonText}>Hide Keyboard</Text>
</View>
</TouchableWithoutFeedback>
</View>
<View style={{flex: 1}} />
<View style={styles.inputBox}>
<TextInput
style={styles.inputBoxText}
placeholder={'Enter Text Here...'}
underlineColorAndroid={'transparent'}
/>
</View>
render: function () {
return (
<View style={styles.container}>
<View style={styles.settingButtons}>
<TouchableWithoutFeedback
onPress={() => this.setKeyboardSetting("nothing")}
>
<View
style={[
styles.settingButton,
this.state.setting == "nothing"
? { backgroundColor: "green" }
: {},
]}
>
<Text style={styles.settingButtonText}>Adjust Nothing</Text>
</View>
);
}
</TouchableWithoutFeedback>
<TouchableWithoutFeedback
onPress={() => this.setKeyboardSetting("pan")}
>
<View
style={[
styles.settingButton,
this.state.setting == "pan" ? { backgroundColor: "green" } : {},
]}
>
<Text style={styles.settingButtonText}>Adjust Pan</Text>
</View>
</TouchableWithoutFeedback>
</View>
<View style={styles.settingButtons}>
<TouchableWithoutFeedback
onPress={() => this.setKeyboardSetting("resize")}
>
<View
style={[
styles.settingButton,
this.state.setting == "resize"
? { backgroundColor: "green" }
: {},
]}
>
<Text style={styles.settingButtonText}>Adjust Resize</Text>
</View>
</TouchableWithoutFeedback>
<TouchableWithoutFeedback
onPress={() => this.setKeyboardSetting("unspecified")}
>
<View
style={[
styles.settingButton,
this.state.setting == "unspecified"
? { backgroundColor: "green" }
: {},
]}
>
<Text style={styles.settingButtonText}>Adjust Unspecified</Text>
</View>
</TouchableWithoutFeedback>
</View>
<View style={styles.settingButtons}>
<TouchableWithoutFeedback onPress={() => dismissKeyboard()}>
<View style={styles.settingButton}>
<Text style={styles.settingButtonText}>Hide Keyboard</Text>
</View>
</TouchableWithoutFeedback>
</View>
<View style={{ flex: 1 }} />
<View style={styles.inputBox}>
<TextInput
style={styles.inputBoxText}
placeholder={"Enter Text Here..."}
underlineColorAndroid={"transparent"}
/>
</View>
</View>
);
},
});

var styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'red',
borderRadius: 20
},
settingButtons: {
flexDirection: 'row',
margin: 5,
marginBottom: 0
},
settingButton: {
flex: 1,
backgroundColor: 'white',
borderRadius: 5,
margin: 5,
marginBottom: 0
},
settingButtonText: {
textAlign: 'center',
color: 'black',
margin: 10
},
inputBox: {
backgroundColor: 'white',
borderRadius: 5,
margin: 10
},
inputBoxText: {
backgroundColor: 'transparent',
},
container: {
flex: 1,
backgroundColor: "red",
borderRadius: 20,
},
settingButtons: {
flexDirection: "row",
margin: 5,
marginBottom: 0,
},
settingButton: {
flex: 1,
backgroundColor: "white",
borderRadius: 5,
margin: 5,
marginBottom: 0,
},
settingButtonText: {
textAlign: "center",
color: "black",
margin: 10,
},
inputBox: {
backgroundColor: "white",
borderRadius: 5,
margin: 10,
},
inputBoxText: {
backgroundColor: "transparent",
},
});

AppRegistry.registerComponent('KeyboardAdjustExample', () => KeyboardAdjustExample);
AppRegistry.registerComponent(
"KeyboardAdjustExample",
() => KeyboardAdjustExample
);

module.exports = KeyboardAdjustExample;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.app.Activity;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
Expand All @@ -16,6 +18,7 @@ public AndroidKeyboardAdjustModule(ReactApplicationContext reactApplicationConte
super(reactApplicationContext);
}


@Override
public String getName() {
return "AndroidKeyboardAdjust";
Expand All @@ -29,7 +32,7 @@ public void setStateUnspecified() {
if (activity == null) {
return;
}

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Expand All @@ -46,7 +49,7 @@ public void setAdjustNothing() {
if (activity == null) {
return;
}

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.zubricky.AndroidKeyboardAdjust;

import com.facebook.react.bridge.ReactApplicationContext;

public class AndroidKeyboardAdjustModuleBuilder {

private ReactApplicationContext reactContext;

public AndroidKeyboardAdjustModuleBuilder withReactContext(ReactApplicationContext reactContext) {
this.reactContext = reactContext;
return this;
}


public AndroidKeyboardAdjustModule build() {
validate();
return new AndroidKeyboardAdjustModule(reactContext);
}

private void validate() {
if (reactContext == null) {
throw new Error("React Context was not provided");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import android.app.Activity;

import androidx.annotation.NonNull;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
Expand All @@ -13,16 +16,29 @@

public class AndroidKeyboardAdjustPackage implements ReactPackage {

private final AndroidKeyboardAdjustModuleBuilder builder;

public AndroidKeyboardAdjustPackage() {
this (new AndroidKeyboardAdjustModuleBuilder());
}

public AndroidKeyboardAdjustPackage(AndroidKeyboardAdjustModuleBuilder builder) {
this.builder = builder;
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactApplicationContext) {
return Collections.<NativeModule>singletonList(new AndroidKeyboardAdjustModule(reactApplicationContext));
}

@NonNull
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactApplicationContext) {
return Arrays.<ViewManager>asList();
@NonNull
public List<ViewManager> createViewManagers(@NonNull final ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
3 changes: 0 additions & 3 deletions index.js

This file was deleted.

19 changes: 19 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NativeModules } from "react-native";

const { AndroidKeyboardAdjust } = NativeModules;

export const adjustResize = () => AndroidKeyboardAdjust.setAdjustResize();

export const adjustPan = () => AndroidKeyboardAdjust.setAdjustPan();

export const adjustNothing = () => AndroidKeyboardAdjust.setAdjustNothing();

export const adjustUnspecified = () =>
AndroidKeyboardAdjust.setAdjustUnspecified();

export default {
adjustResize,
adjustPan,
adjustNothing,
adjustUnspecified,
};
Loading