Commit 4d56c432 by CaryaLiu

feat: iOS相关改动

parent bb8bdbef
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { import {
NativeModules, NativeModules,
NativeEventEmitter,
SafeAreaView, SafeAreaView,
StyleSheet, StyleSheet,
ScrollView, ScrollView,
...@@ -24,6 +25,7 @@ import { ...@@ -24,6 +25,7 @@ import {
import { BMCUI } from './ui.js' import { BMCUI } from './ui.js'
import CustomerView from './CustomerView.js' import CustomerView from './CustomerView.js'
import CustomRoundImageView from './RoundedImage.js' import CustomRoundImageView from './RoundedImage.js'
import MapView from './MapView.js'
import { import {
Header, Header,
...@@ -33,6 +35,9 @@ import { ...@@ -33,6 +35,9 @@ import {
ReloadInstructions, ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen'; } from 'react-native/Libraries/NewAppScreen';
var ToastManager = NativeModules.ToastManager;
var AlertManager = NativeModules.AlertManager;
async function showConfirmVsCancelPromiseDialog(msg, leftTip, rightTip) { async function showConfirmVsCancelPromiseDialog(msg, leftTip, rightTip) {
try { try {
const { const {
...@@ -48,13 +53,42 @@ async function showConfirmVsCancelPromiseDialog(msg, leftTip, rightTip) { ...@@ -48,13 +53,42 @@ async function showConfirmVsCancelPromiseDialog(msg, leftTip, rightTip) {
} }
} }
// class App extends React.Component {
// onRegionChange(event) {
// console.log(event.region.latitude)
// }
// render() {
// const region = {
// latitude: 37.48,
// longitue: -122.16,
// latitudeDelta: 0.1,
// longitudeDelta: 0.1,
// };
// return (
// <MapView
// region={region}
// zoomEnabled={false}
// onRegionChange={this.onRegionChange}
// style={{ flex: 1 }}
// />
// );
// }
// }
const App = () => { const App = () => {
var index = 0; var index = 0;
const region = {
latitude: 37.48,
longitue: -122.16,
latitudeDelta: 0.1,
longitudeDelta: 0.1,
};
return ( return (
<> <>
<StatusBar barStyle="dark-content" /> <StatusBar barStyle="dark-content" />
<SafeAreaView> <SafeAreaView>
<ScrollView <ScrollView
contentInsetAdjustmentBehavior="automatic" contentInsetAdjustmentBehavior="automatic"
style={styles.scrollView}> style={styles.scrollView}>
{global.HermesInternal == null ? null : ( {global.HermesInternal == null ? null : (
...@@ -63,7 +97,8 @@ const App = () => { ...@@ -63,7 +97,8 @@ const App = () => {
</View> </View>
)} )}
<View style={styles.buttonContainer}> <View style={styles.buttonContainer}>
<CustomerView /> <CustomerView style={{height: 80}}/>
<MapView region={region} zoomEnabled={false} style={{ flex: 1, height: 200}} />
</View> </View>
<View style={styles.body}> <View style={styles.body}>
<View style={styles.buttonContainer}> <View style={styles.buttonContainer}>
...@@ -93,7 +128,11 @@ const App = () => { ...@@ -93,7 +128,11 @@ const App = () => {
// NativeModules.BMCUI.showWithDuration("你点击了按钮!", NativeModules.BMCUI.SHORT); // NativeModules.BMCUI.showWithDuration("你点击了按钮!", NativeModules.BMCUI.SHORT);
// Alert.alert("你点击了按钮"); // Alert.alert("你点击了按钮");
} else { } else {
Alert.alert("ios undefine"); // Alert.alert("ios undefine");
// NativeModules.ToastManager
var alerts = "alert..." + NativeModules.AlertManager.alertStyleLight;
console.log(alerts)
AlertManager.showAlert("tesss")
} }
}} }}
title="吐司" title="吐司"
...@@ -115,6 +154,7 @@ const App = () => { ...@@ -115,6 +154,7 @@ const App = () => {
// }, true, "你点击了按钮222!", "确定"); // }, true, "你点击了按钮222!", "确定");
} else { } else {
Alert.alert("ios undefine"); Alert.alert("ios undefine");
} }
}} }}
title="单按钮提示框" title="单按钮提示框"
...@@ -165,9 +205,9 @@ const App = () => { ...@@ -165,9 +205,9 @@ const App = () => {
</View> </View>
<LearnMoreLinks /> <LearnMoreLinks />
</View> </View>
</ScrollView> </ScrollView>
</SafeAreaView> </SafeAreaView>
</> </>
); );
}; };
......
...@@ -5,10 +5,12 @@ import { ...@@ -5,10 +5,12 @@ import {
Image, Image,
TextInput, TextInput,
DeviceEventEmitter, DeviceEventEmitter,
NativeEventEmitter,
TouchableHighlight, TouchableHighlight,
TouchableNativeFeedback, TouchableNativeFeedback,
Platform, Platform,
Alert Alert,
NativeModules
} from 'react-native'; } from 'react-native';
import { BMCUI, ImagePicker } from './ui.js' import { BMCUI, ImagePicker } from './ui.js'
...@@ -73,18 +75,25 @@ export default class CustomerView extends React.Component { ...@@ -73,18 +75,25 @@ export default class CustomerView extends React.Component {
componentDidMount() { componentDidMount() {
console.log("CustomerView componentDidMount"); console.log("CustomerView componentDidMount");
this.eventListener = DeviceEventEmitter.addListener('msg', (a) => { if (Platform.OS == 'android') {
// alert('收到通知:' + a); this.eventListener = DeviceEventEmitter.addListener('msg', (a) => {
console.log("收到通知:" + a); // alert('收到通知:' + a);
if (a && a.test) { console.log("收到通知:" + a);
tip = a.test if (a && a.test) {
} else { tip = a.test
tip = a } else {
} tip = a
BMCUI.showConfirmDialogWithCancelable(false, "收到新消息:" + tip, "确定", (result) => { }
console.log("你点击了取确定按钮,结果为:" + result); BMCUI.showConfirmDialogWithCancelable(false, "收到新消息:" + tip, "确定", (result) => {
console.log("你点击了取确定按钮,结果为:" + result);
});
}); });
}); } else {
const alertEmitter = new NativeEventEmitter(NativeModules.AlertManager)
this.subscription = alertEmitter.addListener('msg', (a) => {
console.log("你收到事件" + a.test);
});
}
} }
shouldComponentUpdate(nextProps, nextState, nextContext) { shouldComponentUpdate(nextProps, nextState, nextContext) {
...@@ -98,7 +107,11 @@ export default class CustomerView extends React.Component { ...@@ -98,7 +107,11 @@ export default class CustomerView extends React.Component {
componentWillUnmount() { componentWillUnmount() {
console.log("CustomerView componentWillUnmount"); console.log("CustomerView componentWillUnmount");
this.eventListener.remove(); // Removes the listener if (Platform.OS == 'android') {
this.eventListener.remove(); // Removes the listener
} else {
this.subscription.remove();
}
} }
componentDidCatch(error, errorInfo) { componentDidCatch(error, errorInfo) {
......
import PropTypes from 'prop-types';
import React from 'react';
import {
requireNativeComponent
} from 'react-native';
class MapView extends React.Component {
_onRegionChange = (event) => {
if (!this.props.onRegionChange) {
return;
}
this.props.onRegionChange(event.nativeEvent);
}
render() {
return (
<RNTMap
{...this.props}
onRegionChange={this._onRegionChange}
/>
);
}
}
MapView.prototypes = {
/**
* A Boolean value that determines whether the user may use pinch
* gestures to zoom in and out of the map.
*/
zoomEnabled: PropTypes.bool,
/**
* 地图要显示的区域。
*
* 区域由中心点坐标和区域范围坐标来定义。
*
*/
region: PropTypes.shape({
/**
* 地图中心点的坐标。
*/
latitude: PropTypes.number.isRequired,
longitude: PropTypes.number.isRequired,
/**
* 最小/最大经、纬度间的距离。
*
*/
latitudeDelta: PropTypes.number.isRequired,
longitudeDelta: PropTypes.number.isRequired,
}),
/**
* Callback that is called continuously when the user is dragging the map.
*/
onRegionChange: PropTypes.func,
};
const RNTMap = requireNativeComponent('RNTMap', MapView);
export default MapView;
\ No newline at end of file
ios @ 34c64df5
Subproject commit b7b2f8ccbd271883333f7aaa95186bfd5a0946bc Subproject commit 34c64df58686624bb36578bba6f101b2745e6693
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment