React
8
Вклад в тег
// my method class
@ReactMethod
public void setCurrentTime(final Integer key, final Float sec) {
MediaPlayer player = this.playerPool.get(key);
if (player != null) {
player.seekTo((int) Math.round(sec * 1000));
}
}
// создается нативный модуль OutputVolume
@implementation OutputVolume
RCT_EXPORT_MODULE();
// Отдает метод get
RCT_REMAP_METHOD(get,
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
float volume = [AVAudioSession sharedInstance].outputVolume;
NSString* volumeString = [NSString stringWithFormat:@"%f", volume];
if (volumeString) {
resolve(volumeString);
} else {
reject(@"get_error", @"Error getting system volume", nil);
}
}
import { NativeModules } from 'react-native';
const MyNativeModule = NativeModules.MyNativeModule;
import React, {Component} from "react";
import {connect} from "react-redux";
import {bindActionCreators} from "redux";
/* ваш компонент */
class MyComponent extends Component {
render() {
console.log(this.props);
return (<div></div>);
}
}
const mapStateToProps = (state) => {
return {
state
}
};
const mapDispatchesToProps = (dispatch) => {
return {
dispatch,
// это мы подключаем собственные actions
actions: bindActionCreators(actions, dispatch),
}
};
export default connect(mapStateToProps, mapDispatchesToProps)(MyComponent);