1 | [![Build Status][check-badge]][workflows]
|
2 | [![npm][npm-badge]][npm]
|
3 | [![react-native][rn-badge]][rn]
|
4 | [![MIT][license-badge]][license]
|
5 | <a href="https://www.jetbrains.com/?from=react-native-material-kit" title="Built with JetBrains IDEs">
|
6 | <img src="http://xinthink.github.io/react-native-material-kit/images/logo_JetBrains_1.svg" alt="Built with JetBrains IDEs" width="48">
|
7 | </a>
|
8 |
|
9 | A set of UI components, in the purpose of introducing [Material Design][md] to apps built with [React Native][rn], quickly and painlessly.
|
10 |
|
11 | [npm-badge]: https://img.shields.io/npm/v/react-native-material-kit.svg
|
12 | [npm]: https://www.npmjs.com/package/react-native-material-kit
|
13 | [rn-badge]: https://img.shields.io/badge/react--native-v0.61-05A5D1.svg
|
14 | [rn]: https://facebook.github.io/react-native
|
15 | [md]: http://www.google.com/design/spec/material-design/introduction.html
|
16 | [license-badge]: https://img.shields.io/dub/l/vibe-d.svg
|
17 | [license]: https://raw.githubusercontent.com/xinthink/react-native-material-kit/master/LICENSE.md
|
18 | [gitter-badge]: https://img.shields.io/gitter/room/xinthink/react-native-material-kit.svg
|
19 | [gitter-rnmk]: https://gitter.im/xinthink/react-native-material-kit
|
20 | [workflows]: https://github.com/xinthink/react-native-material-kit/actions
|
21 | [check-badge]: https://github.com/xinthink/react-native-material-kit/workflows/check/badge.svg
|
22 |
|
23 | ## Getting Started
|
24 |
|
25 | First, `cd` to your RN project directory, and install RNMK through [rnpm](https://github.com/rnpm/rnpm) . If you don't have rnpm, you can install RNMK from npm with the command `npm i -S react-native-material-kit` and link it manually (see below).
|
26 |
|
27 |
|
28 | ## NOTICE:
|
29 |
|
30 | react-native-material-kit >= 0.4.0 only supports react-native >= 0.40.0
|
31 |
|
32 | react-native-material-kit < 0.4.0 only supports react-native < 0.40.0
|
33 |
|
34 | ### iOS
|
35 |
|
36 | * #### React Native < 0.29 (Using rnpm)
|
37 |
|
38 | `rnpm install react-native-material-kit`
|
39 |
|
40 | * #### React Native >= 0.29
|
41 | `npm install -S react-native-material-kit`
|
42 |
|
43 | `react-native link react-native-material-kit`
|
44 |
|
45 |
|
46 |
|
47 | #### Manually
|
48 | 1. Add `node_modules/react-native-material-kit/iOS/RCTMaterialKit.xcodeproj` to your xcode project, usually under the `Libraries` group
|
49 | 1. Add `libRCTMaterialKit.a` (from `Products` under `RCTMaterialKit.xcodeproj`) to build target's `Linked Frameworks and Libraries` list
|
50 |
|
51 | #### Option: Using [CocoaPods](https://cocoapods.org)
|
52 |
|
53 | Assuming you have [CocoaPods](https://cocoapods.org) installed, create a `PodFile` like this in your app's project directory. You can leave out the modules you don't need.
|
54 |
|
55 | ```ruby
|
56 | xcodeproj 'path/to/YourProject.xcodeproj/'
|
57 |
|
58 | pod 'React', :subspecs => ['Core', 'RCTText', 'RCTWebSocket'], :path => 'node_modules/react-native'
|
59 | pod 'react-native-material-kit', :path => 'node_modules/react-native-material-kit'
|
60 |
|
61 | post_install do |installer|
|
62 | target = installer.pods_project.targets.select{|t| 'React' == t.name}.first
|
63 | phase = target.new_shell_script_build_phase('Run Script')
|
64 | phase.shell_script = "if nc -w 5 -z localhost 8081 ; then\n if ! curl -s \"http://localhost:8081/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port 8081 already in use, packager is either not running or not running correctly\"\n exit 2\n fi\nelse\n open $SRCROOT/../node_modules/react-native/packager/launchPackager.command || echo \"Can't start packager automatically\"\nfi"
|
65 | end
|
66 | ```
|
67 |
|
68 | Now run `pod install`. This will create an Xcode workspace containing all necessary native files, including react-native-material-kit. From now on open `YourProject.xcworkspace` instead of `YourProject.xcodeproject` in Xcode. Because React Native's iOS code is now pulled in via CocoaPods, you also need to remove the `React`, `RCTImage`, etc. subprojects from your app's Xcode project, in case they were added previously.
|
69 |
|
70 | ### Android
|
71 |
|
72 | * #### React Native < 0.29 (Using rnpm)
|
73 |
|
74 | `rnpm install react-native-material-kit`
|
75 |
|
76 | * #### React Native >= 0.29
|
77 | `npm install -S react-native-material-kit`
|
78 |
|
79 | `react-native link react-native-material-kit`
|
80 |
|
81 | #### Manually
|
82 | 1. JDK 7+ is required
|
83 | 1. Add the following snippet to your `android/settings.gradle`:
|
84 | ```gradle
|
85 | include ':RNMaterialKit'
|
86 | project(':RNMaterialKit').projectDir = file('../node_modules/react-native-material-kit/android')
|
87 |
|
88 | ```
|
89 | 1. Declare the dependency in your `android/app/build.gradle`
|
90 | ```gradle
|
91 | dependencies {
|
92 | ...
|
93 | compile project(':RNMaterialKit')
|
94 | }
|
95 |
|
96 | ```
|
97 | 1. Import `com.github.xinthink.rnmk.ReactMaterialKitPackage` and register it in your `MainActivity` (or equivalent, RN >= 0.32 MainApplication.java):
|
98 |
|
99 | ```java
|
100 | @Override
|
101 | protected List<ReactPackage> getPackages() {
|
102 | return Arrays.asList(
|
103 | new MainReactPackage(),
|
104 | new ReactMaterialKitPackage()
|
105 | );
|
106 | }
|
107 | ```
|
108 |
|
109 | #### Manual Installation Issues
|
110 | If you experience any trouble manually installing `react-native-material-kit` on Android,
|
111 | you should be able to safely skip it.
|
112 |
|
113 | Finally, you're good to go, feel free to require `react-native-material-kit` in your JS files.
|
114 |
|
115 | Have fun! :metal:
|
116 |
|
117 | ## Resources
|
118 | - [Release Notes]
|
119 | - Refer to the [Annotated Source][docs] as API docs
|
120 | - Source code of [Demo app]
|
121 | - For contributors, please refer to [How to debug local RNMK module][debug-with-demo]
|
122 | - Chat about bugs/features on [Gitter][gitter-rnmk]
|
123 |
|
124 | [docs]: http://xinthink.github.io/react-native-material-kit/docs/index.html
|
125 | [Demo app]: https://github.com/xinthink/react-native-material-kit/tree/master/example
|
126 | [debug-with-demo]: https://github.com/xinthink/rnmk-demo#debugging-local-rnmk-module
|
127 | [Release Notes]: https://github.com/xinthink/react-native-material-kit/releases
|
128 |
|
129 | ## Components
|
130 | - [Buttons](#buttons)
|
131 | - [Cards](#cards)
|
132 | - [Loading](#loading)
|
133 | - [Progress bar](#progress-bar)
|
134 | - [Spinner](#spinner)
|
135 | - [Sliders](#sliders)
|
136 | - [Range Slider](#range-slider)
|
137 | - [Textfields](#text-fields)
|
138 | - [Toggles](#toggles)
|
139 | - [Checkbox](#checkbox)
|
140 | - [Radio button](#radio-button)
|
141 | - [Icon toggle](#icon-toggle)
|
142 | - [Switch](#switch)
|
143 |
|
144 | ### Buttons
|
145 |
|
146 | [![img-buttons]][mdl-buttons]
|
147 |
|
148 | Apply [Material Design Buttons][mdl-buttons] with a few lines of code using predefined builders, which comply with the [Material Design Lite default theme][mdl-theme].
|
149 |
|
150 | ```jsx
|
151 | // colored button with default theme (configurable)
|
152 | const ColoredRaisedButton = MKButton.coloredButton()
|
153 | .withText('BUTTON')
|
154 | .withOnPress(() => {
|
155 | console.log("Hi, it's a colored button!");
|
156 | })
|
157 | .build();
|
158 |
|
159 | ...
|
160 | <ColoredRaisedButton />
|
161 | ```
|
162 |
|
163 | And you can definitely build customized buttons from scratch.
|
164 |
|
165 | with builder:
|
166 |
|
167 | ```jsx
|
168 | const CustomButton = new MKButton.Builder()
|
169 | .withBackgroundColor(MKColor.Teal)
|
170 | .withShadowRadius(2)
|
171 | .withShadowOffset({width:0, height:2})
|
172 | .withShadowOpacity(.7)
|
173 | .withShadowColor('black')
|
174 | .withOnPress(() => {
|
175 | console.log('hi, raised button!');
|
176 | })
|
177 | .withTextStyle({
|
178 | color: 'white',
|
179 | fontWeight: 'bold',
|
180 | })
|
181 | .withText('RAISED BUTTON')
|
182 | .build();
|
183 |
|
184 | ...
|
185 | <CustomButton />
|
186 | ```
|
187 |
|
188 | the jsx equivalent:
|
189 |
|
190 | ```jsx
|
191 | <MKButton
|
192 | backgroundColor={MKColor.Teal}
|
193 | shadowRadius={2}
|
194 | shadowOffset={{width:0, height:2}}
|
195 | shadowOpacity={.7}
|
196 | shadowColor="black"
|
197 | onPress={() => {
|
198 | console.log('hi, raised button!');
|
199 | }}
|
200 | >
|
201 | <Text pointerEvents="none"
|
202 | style={{color: 'white', fontWeight: 'bold',}}>
|
203 | RAISED BUTTON
|
204 | </Text>
|
205 | </MKButton>
|
206 | ```
|
207 |
|
208 | π [props reference][button-props-doc] and [example code][buttons-sample]
|
209 |
|
210 | > Why builders? See the β[Builder vs. configuration object][issue-3]β discussion.
|
211 |
|
212 | [img-buttons]: https://cloud.githubusercontent.com/assets/390805/8888853/69f8d9f8-32f2-11e5-9823-c235ab8c0dd2.gif
|
213 | [mdl-buttons]: http://www.getmdl.io/components/index.html#buttons-section
|
214 | [mdl-theme]: http://www.getmdl.io/customize/index.html
|
215 | [buttons-sample]: https://github.com/xinthink/react-native-material-kit/blob/master/example/app/buttons.js
|
216 | [issue-3]: https://github.com/xinthink/react-native-material-kit/issues/3
|
217 | [button-props-doc]: http://xinthink.github.io/react-native-material-kit/docs/lib/mdl/Button.html#props
|
218 |
|
219 | ### Cards
|
220 | [![img-cards]][cards-mdl]
|
221 |
|
222 | Apply [`Card Style`][cards-mdl] with only few styles !.
|
223 | ```jsx
|
224 | import {
|
225 | getTheme,
|
226 | ...
|
227 | } from 'react-native-material-kit';
|
228 |
|
229 | const theme = getTheme();
|
230 |
|
231 | <View style={theme.cardStyle}>
|
232 | <Image source={{uri : base64Icon}} style={theme.cardImageStyle} />
|
233 | <Text style={theme.cardTitleStyle}>Welcome</Text>
|
234 | <Text style={theme.cardContentStyle}>
|
235 | Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
236 | Mauris sagittis pellentesque lacus eleifend lacinia...
|
237 | </Text>
|
238 | <View style={theme.cardMenuStyle}>{menu}</View>
|
239 | <Text style={theme.cardActionStyle}>My Action</Text>
|
240 | </View>
|
241 |
|
242 | ```
|
243 |
|
244 | π [example code][card-sample]
|
245 |
|
246 | [cards-mdl]: http://www.getmdl.io/components/index.html#cards-section
|
247 | [img-cards]: https://cloud.githubusercontent.com/assets/390805/10262736/4411994a-6a07-11e5-8a72-b7a46ba5e4a9.png
|
248 | [card-sample]: https://github.com/xinthink/react-native-material-kit/blob/master/example/app/cards.js
|
249 |
|
250 | ### Loading
|
251 | [MDL Loading][mdl-loading] components.
|
252 |
|
253 | #### Progress bar
|
254 | [![progress-demo]][mdl-loading]
|
255 |
|
256 | ```jsx
|
257 | <mdl.Progress
|
258 | style={styles.progress}
|
259 | progress={0.2}
|
260 | />
|
261 | ```
|
262 |
|
263 | π [props reference][prog-props-doc] and [example code][progress-sample]
|
264 |
|
265 | #### Spinner
|
266 | [![spinner-demo]][mdl-loading]
|
267 |
|
268 | ```jsx
|
269 | <mdl.Spinner />
|
270 | ```
|
271 |
|
272 | π [props reference][spinner-props-doc] and [example code][progress-sample]
|
273 |
|
274 | [mdl-loading]: http://www.getmdl.io/components/index.html#loading-section
|
275 | [progress-demo]: https://cloud.githubusercontent.com/assets/390805/9288698/01e31432-4387-11e5-98e5-85b18471baeb.gif
|
276 | [spinner-demo]: https://cloud.githubusercontent.com/assets/390805/9291361/6e7a75bc-43ec-11e5-95be-2b33eb7f8734.gif
|
277 | [progress-sample]: https://github.com/xinthink/react-native-material-kit/blob/master/example/app/progress.js
|
278 | [prog-props-doc]: http://xinthink.github.io/react-native-material-kit/docs/lib/mdl/Progress.html#props
|
279 | [spinner-props-doc]: http://xinthink.github.io/react-native-material-kit/docs/lib/mdl/Spinner.ios.html#props
|
280 |
|
281 | ### Sliders
|
282 | [MDL Slider][mdl-slider] components.
|
283 | [![slider-demo]][mdl-slider]
|
284 |
|
285 | ```jsx
|
286 | <mdl.Slider style={styles.slider} />
|
287 | β¦
|
288 | const SliderWithValue = mdl.Slider.slider()
|
289 | .withStyle(styles.slider)
|
290 | .withMin(10)
|
291 | .withMax(100)
|
292 | .build();
|
293 | β¦
|
294 | <SliderWithValue
|
295 | ref="sliderWithValue"
|
296 | onChange={(curValue) => this.setState({curValue})}
|
297 | />
|
298 | ```
|
299 |
|
300 | π [props reference][slider-props-doc] and [example code][slider-sample]
|
301 |
|
302 | ### Range Slider
|
303 | ![range-slider-demo]
|
304 |
|
305 | ```jsx
|
306 | <mdl.RangeSlider style={styles.slider} />
|
307 | β¦
|
308 | const SliderWithRange = mdl.RangeSlider.slider()
|
309 | .withStyle(styles.slider)
|
310 | .withMin(10)
|
311 | .withMax(100)
|
312 | .withMinValue(30)
|
313 | .withMaxValue(50)
|
314 | .build();
|
315 | β¦
|
316 | <SliderWithRange
|
317 | ref="sliderWithRange"
|
318 | onChange={(curValue) => this.setState({
|
319 | min: curValue.min,
|
320 | max: curValue.max,
|
321 | })
|
322 | }
|
323 | onConfirm={(curValue) => {
|
324 | console.log("Slider drag ended");
|
325 | console.log(curValue);
|
326 | }}
|
327 | />
|
328 | ```
|
329 |
|
330 | π [props reference][range-slider-props-doc] and [example code][slider-sample]
|
331 |
|
332 | [mdl-slider]: http://www.getmdl.io/components/index.html#sliders-section
|
333 | [slider-demo]: https://cloud.githubusercontent.com/assets/390805/10123318/6c502e6e-6569-11e5-924a-62c8b850511c.gif
|
334 | [range-slider-demo]: https://cloud.githubusercontent.com/assets/16245422/12763284/63a2dafc-c9a8-11e5-8fde-37b6f42a60c2.gif
|
335 | [slider-sample]: https://github.com/xinthink/react-native-material-kit/blob/master/example/app/sliders.js
|
336 | [slider-props-doc]: http://xinthink.github.io/react-native-material-kit/docs/lib/mdl/Slider.html#props
|
337 | [range-slider-props-doc]: http://xinthink.github.io/react-native-material-kit/docs/lib/mdl/RangeSlider.html#props
|
338 |
|
339 | ### Text Fields
|
340 |
|
341 | Built-in textfields, which comply with [Material Design Lite][mdl-tf].
|
342 |
|
343 | [![img-tf]][mdl-tf]
|
344 |
|
345 | ```jsx
|
346 | // textfield with default theme (configurable)
|
347 | const Textfield = MKTextField.textfield()
|
348 | .withPlaceholder('Text...')
|
349 | .withStyle(styles.textfield)
|
350 | .build();
|
351 |
|
352 | ...
|
353 | <Textfield />
|
354 | ```
|
355 |
|
356 | Customizing textfields through builder:
|
357 |
|
358 | ```jsx
|
359 | const CustomTextfield = mdl.Textfield.textfield()
|
360 | .withPlaceholder("Text...")
|
361 | .withStyle(styles.textfield)
|
362 | .withTintColor(MKColor.Lime)
|
363 | .withTextInputStyle({color: MKColor.Orange})
|
364 | .build();
|
365 | ...
|
366 | <CustomTextfield />
|
367 | ```
|
368 |
|
369 | the jsx equivalent:
|
370 |
|
371 | ```jsx
|
372 | <MKTextField
|
373 | tintColor={MKColor.Lime}
|
374 | textInputStyle={{color: MKColor.Orange}}
|
375 | placeholder=βTextβ¦β
|
376 | style={styles.textfield}
|
377 | />
|
378 | ```
|
379 |
|
380 | π [props reference][tf-props-doc] and [example code][tf-sample]
|
381 |
|
382 | [mdl-tf]: http://www.getmdl.io/components/#textfields-section
|
383 | [img-tf]: https://cloud.githubusercontent.com/assets/390805/9085678/8280484a-3bb1-11e5-9354-a244b0520736.gif
|
384 | [tf-sample]: https://github.com/xinthink/react-native-material-kit/blob/master/example/app/textfields.js
|
385 | [tf-props-doc]: http://xinthink.github.io/react-native-material-kit/docs/lib/mdl/Textfield.html#props
|
386 |
|
387 | ### Toggles
|
388 |
|
389 | [Icon toggle][mdl-icon-toggle] & [Switch][mdl-switch]
|
390 | [![img-toggles]][mdl-toggles]
|
391 |
|
392 | [mdl-toggles]: http://www.getmdl.io/components/index.html#toggles-section
|
393 | [mdl-icon-toggle]: http://www.getmdl.io/components/index.html#toggles-section/icon-toggle
|
394 | [mdl-switch]: http://www.getmdl.io/components/index.html#toggles-section/switch
|
395 | [img-toggles]: https://cloud.githubusercontent.com/assets/390805/8903074/de0ed748-3487-11e5-9448-9ee304e0a6b6.gif
|
396 |
|
397 | #### Icon toggle
|
398 |
|
399 | ```jsx
|
400 | <MKIconToggle
|
401 | checked={true}
|
402 | onCheckedChange={this._onIconChecked}
|
403 | onPress={this._onIconClicked}
|
404 | >
|
405 | <Text
|
406 | pointerEvents="none"
|
407 | style={styles.toggleTextOff}>Off</Text>
|
408 | <Text state_checked={true}
|
409 | pointerEvents="none"
|
410 | style={[styles.toggleText, styles.toggleTextOn]}>On</Text>
|
411 | </MKIconToggle>
|
412 | ```
|
413 |
|
414 | The two `Text` tags here, similar to [State List][android-state-list] in *Android* development, which can give you the flexibility to decide what content and how it is shown for each state of the toggle. For example, you can use [react-native-icons][rn-icons] here, or any other sophisticated contents.
|
415 |
|
416 | π [props reference][icon-toggle-props-doc] and [example code][toggles-sample]
|
417 |
|
418 | [android-state-list]: http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
|
419 | [rn-icons]: http://xinthink.github.io/react-native-material-kit/docs/lib/mdl/Switch.html
|
420 | [icon-toggle-props-doc]: http://xinthink.github.io/react-native-material-kit/docs/lib/mdl/IconToggle.html#props
|
421 |
|
422 | #### Switch
|
423 |
|
424 | ```jsx
|
425 | <mdl.Switch
|
426 | style={styles.appleSwitch}
|
427 | onColor="rgba(255,152,0,.3)"
|
428 | thumbOnColor={MKColor.Orange}
|
429 | rippleColor="rgba(255,152,0,.2)"
|
430 | onPress={() => console.log('orange switch pressed')}
|
431 | onCheckedChange={(e) => console.log('orange switch checked', e)}
|
432 | />
|
433 | ```
|
434 |
|
435 | π [props reference][switch-js-props-doc] and [example code][toggles-sample]
|
436 |
|
437 | [toggles-sample]: https://github.com/xinthink/react-native-material-kit/blob/master/example/app/toggles.js
|
438 | [switch-js-props-doc]: http://xinthink.github.io/react-native-material-kit/docs/lib/mdl/Switch.html#props
|
439 |
|
440 | #### Checkbox
|
441 |
|
442 | [![img-checkbox]][mdl-checkbox]
|
443 |
|
444 | ```jsx
|
445 | <MKCheckbox
|
446 | checked={true}
|
447 | />
|
448 | ```
|
449 |
|
450 | You can customize the styles by changing the global theme, which affects all checkboxes across the whole app.
|
451 |
|
452 | ```js
|
453 | setTheme({checkboxStyle: {
|
454 | fillColor: MKColor.Teal,
|
455 | borderOnColor: MKColor.Teal,
|
456 | borderOffColor: MKColor.Teal,
|
457 | rippleColor: `rgba(${MKColor.RGBTeal},.15)`,
|
458 | }});
|
459 | ```
|
460 |
|
461 | π [props reference][checkbox-props-doc] and [example code][toggles-sample]
|
462 |
|
463 | [mdl-checkbox]: http://www.getmdl.io/components/index.html#toggles-section/checkbox
|
464 | [img-checkbox]: https://cloud.githubusercontent.com/assets/390805/12009445/0f938cee-acb2-11e5-9732-434382f6cd84.gif
|
465 | [checkbox-props-doc]: http://xinthink.github.io/react-native-material-kit/docs/lib/mdl/Checkbox.html#props
|
466 |
|
467 |
|
468 | #### Radio button
|
469 |
|
470 | [![img-radio]][mdl-radio]
|
471 |
|
472 | ```jsx
|
473 | constructor() {
|
474 | super();
|
475 | this.radioGroup = new MKRadioButton.Group();
|
476 | }
|
477 | ...
|
478 | <MKRadioButton
|
479 | checked={true}
|
480 | group={this.radioGroup}
|
481 | />
|
482 | ```
|
483 |
|
484 | You can customize the styles by changing the global theme, which affects all radio buttons across the whole app.
|
485 |
|
486 | ```js
|
487 | setTheme({radioStyle: {
|
488 | fillColor: `rgba(${MKColor.RGBTeal},.8)`,
|
489 | borderOnColor: `rgba(${MKColor.RGBTeal},.6)`,
|
490 | borderOffColor: `rgba(${MKColor.RGBTeal},.3)`,
|
491 | rippleColor: `rgba(${MKColor.RGBTeal},.15)`,
|
492 | }});
|
493 | ```
|
494 |
|
495 | π [props reference][radio-props-doc] and [example code][toggles-sample]
|
496 |
|
497 | [mdl-radio]: http://www.getmdl.io/components/index.html#toggles-section/radio
|
498 | [img-radio]: https://cloud.githubusercontent.com/assets/390805/10442805/bdb08bc0-7188-11e5-8565-4ee0049ad590.gif
|
499 | [radio-props-doc]: http://xinthink.github.io/react-native-material-kit/docs/lib/mdl/RadioButton.html#props
|