mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 01:40:12 +01:00
FIX: Segment Control
This commit is contained in:
parent
440c8000b9
commit
c6c29b87a8
@ -11,10 +11,12 @@ import com.facebook.react.bridge.Arguments;
|
|||||||
import com.facebook.react.bridge.ReadableArray;
|
import com.facebook.react.bridge.ReadableArray;
|
||||||
import com.facebook.react.bridge.WritableMap;
|
import com.facebook.react.bridge.WritableMap;
|
||||||
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class CustomSegmentedControlManager extends SimpleViewManager<CustomSegmentedControlManager.CustomSegmentedControlView> {
|
public class CustomSegmentedControlManager extends SimpleViewManager<CustomSegmentedControlManager.CustomSegmentedControlView> {
|
||||||
public static final String REACT_CLASS = "CustomSegmentedControl";
|
public static final String REACT_CLASS = "CustomSegmentedControl";
|
||||||
private static boolean isRegistered = false;
|
private static boolean isRegistered = false;
|
||||||
|
private static final String TAG = "CustomSegmentedControlManager";
|
||||||
|
|
||||||
public static class CustomSegmentedControlView extends LinearLayout {
|
public static class CustomSegmentedControlView extends LinearLayout {
|
||||||
private TabLayout tabLayout;
|
private TabLayout tabLayout;
|
||||||
@ -46,18 +48,26 @@ public class CustomSegmentedControlManager extends SimpleViewManager<CustomSegme
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setValues(ReadableArray values) {
|
public void setValues(ReadableArray values) {
|
||||||
tabLayout.removeAllTabs();
|
try {
|
||||||
for (int i = 0; i < values.size(); i++) {
|
tabLayout.removeAllTabs();
|
||||||
tabLayout.addTab(tabLayout.newTab().setText(values.getString(i)));
|
for (int i = 0; i < values.size(); i++) {
|
||||||
|
tabLayout.addTab(tabLayout.newTab().setText(values.getString(i)));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Error setting property 'values': " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedIndex(int selectedIndex) {
|
public void setSelectedIndex(int selectedIndex) {
|
||||||
if (selectedIndex >= 0 && selectedIndex < tabLayout.getTabCount()) {
|
try {
|
||||||
TabLayout.Tab tab = tabLayout.getTabAt(selectedIndex);
|
if (selectedIndex >= 0 && selectedIndex < tabLayout.getTabCount()) {
|
||||||
if (tab != null) {
|
TabLayout.Tab tab = tabLayout.getTabAt(selectedIndex);
|
||||||
tab.select();
|
if (tab != null) {
|
||||||
|
tab.select();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Error setting property 'selectedIndex': " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,14 +20,22 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)setValues:(NSArray<NSString *> *)values {
|
- (void)setValues:(NSArray<NSString *> *)values {
|
||||||
[self removeAllSegments];
|
@try {
|
||||||
for (NSUInteger i = 0; i < values.count; i++) {
|
[self removeAllSegments];
|
||||||
[self insertSegmentWithTitle:values[i] atIndex:i animated:NO];
|
for (NSUInteger i = 0; i < values.count; i++) {
|
||||||
|
[self insertSegmentWithTitle:values[i] atIndex:i animated:NO];
|
||||||
|
}
|
||||||
|
} @catch (NSException *exception) {
|
||||||
|
NSLog(@"Error setting property 'values': %@", exception.reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSelectedIndex:(NSNumber *)selectedIndex {
|
- (void)setSelectedIndex:(NSNumber *)selectedIndex {
|
||||||
self.selectedSegmentIndex = selectedIndex.integerValue;
|
@try {
|
||||||
|
self.selectedSegmentIndex = selectedIndex.integerValue;
|
||||||
|
} @catch (NSException *exception) {
|
||||||
|
NSLog(@"Error setting property 'selectedIndex': %@", exception.reason);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onChange:(UISegmentedControl *)sender {
|
- (void)onChange:(UISegmentedControl *)sender {
|
||||||
|
@ -33,8 +33,10 @@ import loc, { formatBalance } from '../../loc';
|
|||||||
import { BitcoinUnit, Chain } from '../../models/bitcoinUnits';
|
import { BitcoinUnit, Chain } from '../../models/bitcoinUnits';
|
||||||
import { SuccessView } from '../send/success';
|
import { SuccessView } from '../send/success';
|
||||||
import { useStorage } from '../../hooks/context/useStorage';
|
import { useStorage } from '../../hooks/context/useStorage';
|
||||||
import { AddressTypeTabs, TABS } from '../../components/addresses/AddressTypeTabs';
|
|
||||||
import { HandOffActivityType } from '../../components/types';
|
import { HandOffActivityType } from '../../components/types';
|
||||||
|
import SegmentedControl from '../../components/SegmentControl';
|
||||||
|
|
||||||
|
const segmentControlValues = [loc.wallets.details_address, loc.bip47.payment_code];
|
||||||
|
|
||||||
const ReceiveDetails = () => {
|
const ReceiveDetails = () => {
|
||||||
const { walletID, address } = useRoute().params;
|
const { walletID, address } = useRoute().params;
|
||||||
@ -49,7 +51,7 @@ const ReceiveDetails = () => {
|
|||||||
const [showPendingBalance, setShowPendingBalance] = useState(false);
|
const [showPendingBalance, setShowPendingBalance] = useState(false);
|
||||||
const [showConfirmedBalance, setShowConfirmedBalance] = useState(false);
|
const [showConfirmedBalance, setShowConfirmedBalance] = useState(false);
|
||||||
const [showAddress, setShowAddress] = useState(false);
|
const [showAddress, setShowAddress] = useState(false);
|
||||||
const [currentTab, setCurrentTab] = useState(TABS.EXTERNAL);
|
const [currentTab, setCurrentTab] = useState(segmentControlValues[0]);
|
||||||
const { goBack, setParams } = useExtendedNavigation();
|
const { goBack, setParams } = useExtendedNavigation();
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
const [intervalMs, setIntervalMs] = useState(5000);
|
const [intervalMs, setIntervalMs] = useState(5000);
|
||||||
@ -431,9 +433,9 @@ const ReceiveDetails = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderTabContent = () => {
|
const renderTabContent = () => {
|
||||||
const qrValue = currentTab === TABS.EXTERNAL ? bip21encoded : wallet.getBIP47PaymentCode();
|
const qrValue = currentTab === segmentControlValues[0] ? bip21encoded : wallet.getBIP47PaymentCode();
|
||||||
|
|
||||||
if (currentTab === TABS.EXTERNAL) {
|
if (currentTab === segmentControlValues[0]) {
|
||||||
return <View style={styles.container}>{address && renderReceiveDetails()}</View>;
|
return <View style={styles.container}>{address && renderReceiveDetails()}</View>;
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
@ -457,14 +459,17 @@ const ReceiveDetails = () => {
|
|||||||
<View style={[styles.root, stylesHook.root]}>
|
<View style={[styles.root, stylesHook.root]}>
|
||||||
{wallet.isBIP47Enabled() && (
|
{wallet.isBIP47Enabled() && (
|
||||||
<View style={styles.tabsContainer}>
|
<View style={styles.tabsContainer}>
|
||||||
<AddressTypeTabs
|
<SegmentedControl
|
||||||
currentTab={currentTab}
|
values={Object.values(segmentControlValues).map(tab => tab)}
|
||||||
setCurrentTab={setCurrentTab}
|
selectedIndex={Object.values(segmentControlValues).findIndex(tab => tab === currentTab)}
|
||||||
customTabText={{ EXTERNAL: 'Address', INTERNAL: 'Payment Code' }}
|
onChange={index => {
|
||||||
|
const tabKey = Object.keys(segmentControlValues)[index];
|
||||||
|
setCurrentTab(segmentControlValues[tabKey]);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
{renderTabContent()}
|
{showAddress && renderTabContent()}
|
||||||
<View style={styles.share}>
|
<View style={styles.share}>
|
||||||
<BlueCard>
|
<BlueCard>
|
||||||
<Button onPress={handleShareButtonPressed} title={loc.receive.details_share} />
|
<Button onPress={handleShareButtonPressed} title={loc.receive.details_share} />
|
||||||
@ -506,7 +511,9 @@ const styles = StyleSheet.create({
|
|||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
},
|
},
|
||||||
tabsContainer: {
|
tabsContainer: {
|
||||||
height: 65,
|
margin: 40,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
},
|
},
|
||||||
scrollBody: {
|
scrollBody: {
|
||||||
marginTop: 32,
|
marginTop: 32,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React, { useCallback, useEffect, useLayoutEffect, useRef, useReducer, useMemo } from 'react';
|
import React, { useCallback, useEffect, useLayoutEffect, useRef, useReducer, useMemo } from 'react';
|
||||||
import { useFocusEffect, useRoute, RouteProp } from '@react-navigation/native';
|
import { useFocusEffect, useRoute, RouteProp } from '@react-navigation/native';
|
||||||
import { ActivityIndicator, FlatList, StyleSheet, View } from 'react-native';
|
import { ActivityIndicator, FlatList, Platform, StyleSheet, View } from 'react-native';
|
||||||
import { WatchOnlyWallet } from '../../class';
|
import { WatchOnlyWallet } from '../../class';
|
||||||
import { AddressItem } from '../../components/addresses/AddressItem';
|
import { AddressItem } from '../../components/addresses/AddressItem';
|
||||||
import { useTheme } from '../../components/themes';
|
import { useTheme } from '../../components/themes';
|
||||||
@ -200,6 +200,8 @@ const WalletAddresses: React.FC = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const segmentControlMargin = { marginHorizontal: Platform.OS === 'ios' ? 40 : 0 };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[styles.root, stylesHook.root]}>
|
<View style={[styles.root, stylesHook.root]}>
|
||||||
<FlatList
|
<FlatList
|
||||||
@ -213,7 +215,7 @@ const WalletAddresses: React.FC = () => {
|
|||||||
centerContent={!showAddresses}
|
centerContent={!showAddresses}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
ListHeaderComponent={
|
ListHeaderComponent={
|
||||||
<View style={styles.segmentController}>
|
<View style={[styles.segmentController, segmentControlMargin]}>
|
||||||
<SegmentedControl
|
<SegmentedControl
|
||||||
values={Object.values(TABS).map(tab => loc.addresses[`type_${tab}`])}
|
values={Object.values(TABS).map(tab => loc.addresses[`type_${tab}`])}
|
||||||
selectedIndex={Object.values(TABS).findIndex(tab => tab === currentTab)}
|
selectedIndex={Object.values(TABS).findIndex(tab => tab === currentTab)}
|
||||||
@ -236,8 +238,6 @@ const styles = StyleSheet.create({
|
|||||||
flex: 1,
|
flex: 1,
|
||||||
},
|
},
|
||||||
segmentController: {
|
segmentController: {
|
||||||
margin: 40,
|
|
||||||
height: 40,
|
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user