Skip to content

Support PickerView height customization both for IOS and android #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions android/android.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
17 changes: 17 additions & 0 deletions android/src/main/java/com/beefe/picker/PickerViewModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
private static final String PICKER_TEXT_SIZE = "pickerFontSize";
private static final String PICKER_TEXT_ELLIPSIS_LEN = "pickerTextEllipsisLen";

private static final String PICKER_ITEMS_VISIBLE_COUNT = "androidItemsVisibleCount";

private static final String PICKER_FONT_FAMILY = "pickerFontFamily";

private static final String PICKER_EVENT_NAME = "pickerEvent";
Expand Down Expand Up @@ -300,6 +302,19 @@ public void onClick(View v) {
}
}

int pickerVisibleItemsCount = 9;
if (options.hasKey(PICKER_ITEMS_VISIBLE_COUNT)) {
try {
pickerVisibleItemsCount = options.getInt(PICKER_ITEMS_VISIBLE_COUNT);
} catch (Exception e) {
pickerVisibleItemsCount = (int) options.getDouble(PICKER_ITEMS_VISIBLE_COUNT);
}

if(pickerVisibleItemsCount %2 ==0){
pickerVisibleItemsCount++;
}
}

ReadableArray pickerData = options.getArray(PICKER_DATA);

int pickerViewHeight;
Expand All @@ -313,6 +328,7 @@ public void onClick(View v) {
pickerViewLinkage.setPickerData(pickerData, weights);
pickerViewLinkage.setTextColor(pickerTextColor);
pickerViewLinkage.setTextSize(pickerTextSize);
pickerViewLinkage.setItemsVisibleCount(pickerVisibleItemsCount);
pickerViewLinkage.setTextEllipsisLen(pickerTextEllipsisLen);
pickerViewLinkage.setIsLoop(isLoop);

Expand All @@ -333,6 +349,7 @@ public void onSelected(ArrayList<ReturnData> selectedList) {
pickerViewAlone.setPickerData(pickerData, weights);
pickerViewAlone.setTextColor(pickerTextColor);
pickerViewAlone.setTextSize(pickerTextSize);
pickerViewAlone.setItemsVisibleCount(pickerVisibleItemsCount);
pickerViewAlone.setTextEllipsisLen(pickerTextEllipsisLen);
pickerViewAlone.setIsLoop(isLoop);

Expand Down
6 changes: 6 additions & 0 deletions android/src/main/java/com/beefe/picker/view/LoopView.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ public final void setItems(List<String> items) {
invalidate();
}

public final void setItemsVisibleCount(int itemsVisibleCount){
this.itemsVisible=itemsVisibleCount;
remeasure();
invalidate();
}

public String getIndexItem(int index) {
return items.get(index);
}
Expand Down
11 changes: 11 additions & 0 deletions android/src/main/java/com/beefe/picker/view/PickerViewAlone.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ public void setTextSize(float size){
}
}

public void setItemsVisibleCount(int count){
int viewCount = pickerViewAloneLayout.getChildCount();
for (int i = 0; i < viewCount; i++) {
View view = pickerViewAloneLayout.getChildAt(i);
if (view instanceof LoopView) {
LoopView loopView = (LoopView) view;
loopView.setItemsVisibleCount(count);
}
}
}

public void setTypeface(Typeface typeface){
int viewCount = pickerViewAloneLayout.getChildCount();
for (int i = 0; i < viewCount; i++) {
Expand Down
14 changes: 14 additions & 0 deletions android/src/main/java/com/beefe/picker/view/PickerViewLinkage.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,20 @@ public void setTextSize(float size){
}
}

public void setItemsVisibleCount(int count){
switch (curRow) {
case 2:
loopViewOne.setItemsVisibleCount(count);
loopViewTwo.setItemsVisibleCount(count);
break;
case 3:
loopViewOne.setItemsVisibleCount(count);
loopViewTwo.setItemsVisibleCount(count);
loopViewThree.setItemsVisibleCount(count);
break;
}
}

public void setTypeface(Typeface typeface){
switch (curRow) {
case 2:
Expand Down
20 changes: 20 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,24 @@ export default class Picker {
* @memberof Picker
*/
static isPickerShow(fn?: (err: any, message: any) => void): boolean

/**
* Row height of the ios picker view, ios and android are different
*
* Default is 250
*
* @type {number}
* @memberof PickerOptions
*/
iosPickerHeight?: number

/**
* Max items of the picker can display (Workaround for set the picker view height on android)
*
* Default is 9
*
* @type {number}
* @memberof PickerOptions
*/
androidItemsVisibleCount?: number
}
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const options = {
onPickerSelect(){},
pickerToolBarFontSize: 16,
pickerFontSize: 16,
pickerFontColor: [31, 31 ,31, 1]
pickerFontColor: [31, 31 ,31, 1],
iosPickerHeight: 250,
androidItemsVisibleCount: 9
};

export default {
Expand Down
3 changes: 2 additions & 1 deletion ios/RCTBEEPickerManager/RCTBEEPickerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ + (BOOL)requiresMainQueueSetup
NSString *pickerFontFamily=[NSString stringWithFormat:@"%@",indic[@"pickerFontFamily"]];
NSArray *pickerFontColor=indic[@"pickerFontColor"];
NSString *pickerRowHeight=indic[@"pickerRowHeight"];
NSString *pickerHeight=indic[@"iosPickerHeight"];
id pickerData=indic[@"pickerData"];

NSMutableDictionary *dataDic=[[NSMutableDictionary alloc]init];
Expand All @@ -75,7 +76,7 @@ + (BOOL)requiresMainQueueSetup
}];

if ([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0 ) {
self.height=250;
self.height=[pickerHeight integerValue];
}else{
self.height=220;
}
Expand Down