Skip to content

Instantly share code, notes, and snippets.

@stan229
stan229 / index.js
Created March 14, 2017 15:12
React Navigation and Redux example
import React, { Component } from "react";
import { Text } from "react-native";
import { Provider, connect } from "react-redux";
import { StackNavigator, addNavigationHelpers } from "react-navigation";
import Routes from "./config/routes";
import getStore from "./store";
const AppNavigator = StackNavigator(Routes);
@stan229
stan229 / index.js
Created March 14, 2017 04:19
React Navigation sample
import React, { Component } from "react";
import { AppRegistry, View, Text, Button } from "react-native";
import { StackNavigator } from "react-navigation";
const LoginScreen = props => (
<View>
<Button
title="Log In"
onPress={() => {
import React, { Component } from 'react';
import {
View,
Text,
TouchableOpacity
} from 'react-native';
class MyComponent extends Component {
componentWillMount() {
@stan229
stan229 / MediaController.m
Created October 15, 2015 05:00
Full Implementation
#import "MediaController.h"
#import "AppDelegate.h"
@implementation MediaController
RCT_EXPORT_MODULE();
@synthesize bridge = _bridge;
'use strict';
var React = require('react-native');
var MediaController = require('NativeModules').MediaController;
var {
AppRegistry,
StyleSheet,
Text,
TouchableHighlight,
@stan229
stan229 / MediaController.m
Created October 15, 2015 04:48
Communicating with React Native app
-(void) mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
MPMediaItem *mediaItem = mediaItemCollection.items[0];
NSURL *assetURL = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
[self.bridge.eventDispatcher sendAppEventWithName:@"SongPlaying" body:[mediaItem valueForProperty:MPMediaItemPropertyTitle]];
//...
}
@stan229
stan229 / MediaController.m
Created October 15, 2015 04:46
Showing and Hiding MPMediaPlayerController instance
-(void)showMediaPicker {
if(self.mediaPicker == nil) {
self.mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
[self.mediaPicker setDelegate:self];
[self.mediaPicker setAllowsPickingMultipleItems:NO];
[self.mediaPicker setShowsCloudItems:NO];
self.mediaPicker.prompt = @"Select song";
}
#import <Foundation/Foundation.h>
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
#import <MediaPlayer/MediaPlayer.h>
@import AVFoundation;
@interface MediaController : NSObject<RCTBridgeModule,MPMediaPickerControllerDelegate, AVAudioPlayerDelegate>
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"MCDJ"
initialProperties:nil
launchOptions:launchOptions];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view = rootView;
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) UIViewController *rootViewController;
@end