Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a55b6a6
Showing
62 changed files
with
5,375 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["react-native"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
[android] | ||
target = Google Inc.:Google APIs:23 | ||
|
||
[maven_repositories] | ||
central = https://repo1.maven.org/maven2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es6": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"experimentalObjectRestSpread": true, | ||
"jsx": true | ||
}, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"react" | ||
], | ||
"rules": { | ||
"react/jsx-uses-react": "error", | ||
"react/jsx-uses-vars": "error", | ||
"indent": [ | ||
"error", | ||
2 | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
[ignore] | ||
; We fork some components by platform | ||
.*/*[.]android.js | ||
|
||
; Ignore "BUCK" generated dirs | ||
<PROJECT_ROOT>/\.buckd/ | ||
|
||
; Ignore unexpected extra "@providesModule" | ||
.*/node_modules/.*/node_modules/fbjs/.* | ||
|
||
; Ignore duplicate module providers | ||
; For RN Apps installed via npm, "Libraries" folder is inside | ||
; "node_modules/react-native" but in the source repo it is in the root | ||
.*/Libraries/react-native/React.js | ||
.*/Libraries/react-native/ReactNative.js | ||
|
||
[include] | ||
|
||
[libs] | ||
node_modules/react-native/Libraries/react-native/react-native-interface.js | ||
node_modules/react-native/flow | ||
flow/ | ||
|
||
[options] | ||
module.system=haste | ||
|
||
experimental.strict_type_args=true | ||
|
||
munge_underscores=true | ||
|
||
module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub' | ||
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' | ||
|
||
suppress_type=$FlowIssue | ||
suppress_type=$FlowFixMe | ||
suppress_type=$FixMe | ||
|
||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-5]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-5]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy | ||
|
||
unsafe.enable_getters_and_setters=true | ||
|
||
[version] | ||
^0.35.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pbxproj -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# OSX | ||
# | ||
.DS_Store | ||
|
||
# Xcode | ||
# | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
project.xcworkspace | ||
|
||
# Android/IntelliJ | ||
# | ||
build/ | ||
.idea | ||
.gradle | ||
local.properties | ||
*.iml | ||
|
||
# node.js | ||
# | ||
node_modules/ | ||
npm-debug.log | ||
|
||
# BUCK | ||
buck-out/ | ||
\.buckd/ | ||
android/app/libs | ||
*.keystore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# react-native-global-props | ||
A simple javascript implementation to add custom, default props to react-native components. | ||
|
||
## Ever wish you could set global styles that would apply to react-native components like in CSS? | ||
```css | ||
body { | ||
background-color: 'teal' | ||
} | ||
p { | ||
fontSize: 12, | ||
fontFamily: 'Helvetica Neue' | ||
} | ||
``` | ||
or get rid of that ugly line at the bottom of every `TextInput` in Android? | ||
|
||
![](https://cloud.githubusercontent.com/assets/21032419/20550016/7c1ce4b8-b16c-11e6-8b06-f4283e374d75.png) | ||
|
||
## BLEGH! Now you can! | ||
|
||
### Installation | ||
```bash | ||
npm i react-native-global-props --save | ||
``` | ||
### How to use | ||
__The source code can be found under `example/`.__ | ||
|
||
Once you've installed react-native-global-props, go ahead choose which components you want to add custom props to. | ||
In my example, I want to customize the `View`, `TextInput`, `Text`, `Image`, and `TouchableOpacity`. | ||
|
||
Go to your highest order component that contains your whole application. __In my case that is `example/Main.js`.__ | ||
|
||
First I import the `set` functions that will allow me to create my custom components. | ||
```js | ||
import { | ||
setCustomView, | ||
setCustomTextInput, | ||
setCustomText, | ||
setCustomImage, | ||
setCustomTouchableOpacity | ||
} from 'react-native-global-props'; | ||
``` | ||
Then I create the custom props I want to add to each of these components. | ||
```js | ||
// Setting a default background color for all View components. | ||
const customViewProps = { | ||
style: { | ||
backgroundColor: '#d3d3d3' // light gray | ||
} | ||
}; | ||
|
||
// Getting rid of that ugly line on Android and adding some custom style to all TextInput components. | ||
const customTextInputProps = { | ||
underlineColorAndroid: 'rgba(0,0,0,0)', | ||
style: { | ||
borderWidth: 1, | ||
borderColor: 'gray', | ||
paddingVertical: 5, | ||
paddingHorizontal: 10, | ||
backgroundColor: 'white' | ||
} | ||
}; | ||
|
||
// Setting default styles for all Text components. | ||
const customTextProps = { | ||
style: { | ||
fontSize: 16, | ||
fontFamily: Platform.OS === 'ios' ? 'HelveticaNeue' : 'Roboto', | ||
color: 'black' | ||
} | ||
}; | ||
|
||
// Makes every image resize mode cover by default. | ||
const customImageProps = { | ||
resizeMode: 'cover' | ||
}; | ||
|
||
// Adds a bigger hit box for all TouchableOpacity's. | ||
const customTouchableOpacityProps = { | ||
hitSlop: { top: 15, right: 15, left: 15, bottom: 15 } | ||
}; | ||
``` | ||
You can pass in any valid props as seen on __react-native__ documentation. All of these props can easily be overridden. | ||
|
||
Now plug your custom props into the `set` functions like so | ||
```js | ||
setCustomView(customViewProps); | ||
setCustomTextInput(customTextInputProps); | ||
setCustomText(customTextProps); | ||
setCustomImage(customImageProps); | ||
setCustomTouchableOpacity(customTouchableOpacityProps); | ||
``` | ||
And __Voila__, your react-native components will have these certain props wherever you use them. | ||
|
||
Here is an example of me using the components and overriding props. __The below source code can be found in `example/src/App.js`__ | ||
```js | ||
import React from 'react'; | ||
import { | ||
View, | ||
TextInput, | ||
Text, | ||
Image, | ||
TouchableOpacity | ||
} from 'react-native'; | ||
|
||
const images = { | ||
whosThatCoolCat: require('./img/MyNormPic.jpeg') | ||
}; | ||
|
||
class App extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
inputValue: '', | ||
hiddenText: true | ||
} | ||
} | ||
render() { | ||
return ( | ||
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> | ||
<Text style={{ marginBottom: 20 }}>react-native-global-props</Text> | ||
<Image | ||
source={images.whosThatCoolCat} | ||
style={{ width: 80, height: 80, borderRadius: 40 }} | ||
/> | ||
<View style={{ marginVertical: 20 }}> | ||
<TextInput | ||
style={{ width: 200, height: 30 }} | ||
placeholder="Enter text" | ||
onChangeText={(text) => this.setState({ inputValue: text })} | ||
value={this.state.inputValue} | ||
/> | ||
</View> | ||
<TouchableOpacity onPress={() => this.setState({ hiddenText: !this.state.hiddenText })}> | ||
<View style={{ backgroundColor: 'orange' }}> | ||
<Text style={{ color: 'white' }}>Press me to show or hide the input text</Text> | ||
</View> | ||
</TouchableOpacity> | ||
<Text style={{ color: 'red' }}>{this.state.inputValue}</Text> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
export default App; | ||
``` | ||
|
||
And this is the result | ||
![react-native-global-props demo](http://i.giphy.com/2cpQ18KG8L3fa.gif) | ||
|
||
This module is useful for, | ||
1.) Creating an amazing modular experience with your react-native components | ||
2.) Adding customization to react-native components without having to create completely new ones | ||
3.) Setting global styles like fontFamily and color | ||
And much more! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import re | ||
|
||
# To learn about Buck see [Docs](https://buckbuild.com/). | ||
# To run your application with Buck: | ||
# - install Buck | ||
# - `npm start` - to start the packager | ||
# - `cd android` | ||
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` | ||
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck | ||
# - `buck install -r android/app` - compile, install and run application | ||
# | ||
|
||
lib_deps = [] | ||
for jarfile in glob(['libs/*.jar']): | ||
name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile) | ||
lib_deps.append(':' + name) | ||
prebuilt_jar( | ||
name = name, | ||
binary_jar = jarfile, | ||
) | ||
|
||
for aarfile in glob(['libs/*.aar']): | ||
name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile) | ||
lib_deps.append(':' + name) | ||
android_prebuilt_aar( | ||
name = name, | ||
aar = aarfile, | ||
) | ||
|
||
android_library( | ||
name = 'all-libs', | ||
exported_deps = lib_deps | ||
) | ||
|
||
android_library( | ||
name = 'app-code', | ||
srcs = glob([ | ||
'src/main/java/**/*.java', | ||
]), | ||
deps = [ | ||
':all-libs', | ||
':build_config', | ||
':res', | ||
], | ||
) | ||
|
||
android_build_config( | ||
name = 'build_config', | ||
package = 'com.reactnativeglobalprops', | ||
) | ||
|
||
android_resource( | ||
name = 'res', | ||
res = 'src/main/res', | ||
package = 'com.reactnativeglobalprops', | ||
) | ||
|
||
android_binary( | ||
name = 'app', | ||
package_type = 'debug', | ||
manifest = 'src/main/AndroidManifest.xml', | ||
keystore = '//android/keystores:debug', | ||
deps = [ | ||
':app-code', | ||
], | ||
) |
Oops, something went wrong.