Skip to content

Commit

Permalink
Merge pull request #62 from hansemannn/MOD-2287
Browse files Browse the repository at this point in the history
[MOD-2287] iOS/Android: Add missing login button properties
  • Loading branch information
cheekiatng authored Oct 24, 2016
2 parents 50fb764 + 3385a9a commit 9237d10
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 27 deletions.
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 6.0.1
version: 6.1.0
apiversion: 3
architectures: armeabi-v7a x86
description: facebook
Expand Down
29 changes: 28 additions & 1 deletion android/src/facebook/LoginButtonView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import com.facebook.CallbackManager;
import com.facebook.login.DefaultAudience;
import com.facebook.login.widget.LoginButton;

import com.facebook.login.widget.ToolTipPopup;
import com.facebook.login.widget.LoginButton.ToolTipMode;

public class LoginButtonView extends TiUIView {

Expand Down Expand Up @@ -79,6 +80,32 @@ public void processProperties(KrollDict props)
break;
}
}
if (props.containsKey("tooltipBehavior")) {
Object value = props.get("tooltipBehavior");
int tooltipBehavior = TiConvert.toInt(value, TiFacebookModule.LOGIN_BUTTON_TOOLTIP_BEHAVIOR_AUTOMATIC);

switch (tooltipBehavior) {
case TiFacebookModule.LOGIN_BUTTON_TOOLTIP_BEHAVIOR_AUTOMATIC:
loginButton.setToolTipMode(ToolTipMode.AUTOMATIC);
break;
case TiFacebookModule.LOGIN_BUTTON_TOOLTIP_BEHAVIOR_FORCE_DISPLAY:
loginButton.setToolTipMode(ToolTipMode.DISPLAY_ALWAYS);
break;
case TiFacebookModule.LOGIN_BUTTON_TOOLTIP_BEHAVIOR_DISABLE:
loginButton.setToolTipMode(ToolTipMode.NEVER_DISPLAY);
break;
}
}
if (props.containsKey("tooltipColorStyle")) {
Object value = props.get("tooltipColorStyle");
String tooltipColorStyle = TiConvert.toString(value, TiFacebookModule.LOGIN_BUTTON_TOOLTIP_STYLE_NEUTRAL_GRAY);

if (tooltipColorStyle.equals(TiFacebookModule.LOGIN_BUTTON_TOOLTIP_STYLE_NEUTRAL_GRAY)) {
loginButton.setToolTipStyle(ToolTipPopup.Style.BLACK);
} else if (tooltipColorStyle.equals(TiFacebookModule.LOGIN_BUTTON_TOOLTIP_STYLE_FRIENDLY_BLUE)) {
loginButton.setToolTipStyle(ToolTipPopup.Style.BLUE);
}
}
}

@Override
Expand Down
9 changes: 8 additions & 1 deletion android/src/facebook/TiFacebookModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ public class TiFacebookModule extends KrollModule implements OnActivityResultEve
@Kroll.constant public static final String LOGIN_BEHAVIOR_NATIVE = "NATIVE_ONLY";
@Kroll.constant public static final String LOGIN_BEHAVIOR_NATIVE_WITH_FALLBACK = "NATIVE_WITH_FALLBACK";
@Kroll.constant public static final String LOGIN_BEHAVIOR_DEVICE_AUTH = "DEVICE_AUTH";


@Kroll.constant public static final int LOGIN_BUTTON_TOOLTIP_BEHAVIOR_AUTOMATIC = 0;
@Kroll.constant public static final int LOGIN_BUTTON_TOOLTIP_BEHAVIOR_FORCE_DISPLAY = 1;
@Kroll.constant public static final int LOGIN_BUTTON_TOOLTIP_BEHAVIOR_DISABLE = 2;

@Kroll.constant public static final String LOGIN_BUTTON_TOOLTIP_STYLE_NEUTRAL_GRAY = "NEUTRAL_GRAY";
@Kroll.constant public static final String LOGIN_BUTTON_TOOLTIP_STYLE_FRIENDLY_BLUE = "FRIENDLY_BLUE";

@Kroll.constant public static final int SHARE_DIALOG_MODE_AUTOMATIC = 0;
@Kroll.constant public static final int SHARE_DIALOG_MODE_NATIVE = 1;
@Kroll.constant public static final int SHARE_DIALOG_MODE_WEB = 2;
Expand Down
39 changes: 39 additions & 0 deletions apidoc/Facebook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,45 @@ properties:
since: 4.0.0
platforms: [android]

- name: LOGIN_BUTTON_TOOLTIP_BEHAVIOR_AUTOMATIC
summary: |
The default behavior. The tooltip will only be displayed if the app is eligible
(determined by possible server round trip).
type: Number
permission: read-only
since: "6.1.0"
platforms: [iphone, ipad, android]

- name: LOGIN_BUTTON_TOOLTIP_BEHAVIOR_FORCE_DISPLAY
summary: Force display of the tooltip (typically for UI testing).
type: Number
permission: read-only
since: "6.1.0"
platforms: [iphone, ipad, android]

- name: LOGIN_BUTTON_TOOLTIP_BEHAVIOR_DISABLE
summary: |
Force disable. In this case you can still exert more refined control by manually
constructing a new login button.
type: Number
permission: read-only
since: "6.1.0"
platforms: [iphone, ipad, android]

- name: LOGIN_BUTTON_TOOLTIP_STYLE_NEUTRAL_GRAY
summary: Dark gray background, white text, light gray close button.
type: Number
permission: read-only
since: "6.1.0"
platforms: [iphone, ipad, android]

- name: LOGIN_BUTTON_TOOLTIP_STYLE_FRIENDLY_BLUE
summary: Light blue background, white text, faded blue close button.
type: Number
permission: read-only
since: "6.1.0"
platforms: [iphone, ipad, android]

- name: SSO_WITH_FALLBACK
summary: Attempt single sign-on, then fallback to dialog authorization.
description: |
Expand Down
17 changes: 15 additions & 2 deletions apidoc/LoginButton.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,23 @@ properties:
type: Array<String>
since: 4.0.0

- name: tooltipBehavior
summary: Gets or sets the desired tooltip behavior.
constants: [Modules.Facebook.LOGIN_BUTTON_TOOLTIP_BEHAVIOR_*]
since: "6.1.0"
platforms: [iphone, ipad, android]

- name: tooltipColorStyle
summary: Gets or sets the desired tooltip color style.
constants: [Modules.Facebook.LOGIN_BUTTON_TOOLTIP_STYLE_*]
since: "6.1.0"
platforms: [iphone, ipad, android]

- name: sessionLoginBehavior
summary: Login behavior for the session.
since: 4.0.0
removed: 5.0.0
deprecated:
since: 4.0.0
removed: 5.0.0
platforms: [android]
type: Number
default: Modules.Facebook.SSO_WITH_FALLBACK
Expand Down
78 changes: 59 additions & 19 deletions ios/Classes/FacebookLoginButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,82 @@ -(void)dealloc
[super dealloc];
}

-(FBSDKLoginButton*)login
-(FBSDKLoginButton*)loginButton
{
if (login == nil) {
login = [[FBSDKLoginButton alloc] init];
login = [FBSDKLoginButton new];
[self addSubview:login];
}
return login;
}

-(void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds
{
[TiUtils setView:[self login] positionRect:bounds];
[TiUtils setView:[self loginButton] positionRect:bounds];
}

//Requested permissions when logging in. If set, do not set read permissions.
//audience defaults to AUDIENCE_ONLY_ME if not specifically set
-(void)setPublishPermissions_:(id)publishPermissions
// Requested permissions when logging in. If set, do not set read permissions
// The audience defaults to AUDIENCE_ONLY_ME if not specifically set.
-(void)setPublishPermissions_:(id)args
{
ENSURE_ARRAY(publishPermissions);
FBSDKLoginButton *loginBtn = [self login];
loginBtn.publishPermissions = publishPermissions;
ENSURE_ARRAY(args);
[[self loginButton] setPublishPermissions:args];
}

//Requested permissions when logging in. If set, do not set publish permissions.
-(void)setReadPermissions_:(id)readPermissions
-(NSArray*)publishPermissions
{
ENSURE_ARRAY(readPermissions);
FBSDKLoginButton *loginBtn = [self login];
loginBtn.readPermissions = readPermissions;
return [[self loginButton] publishPermissions];
}

//default is AUDIENCE_ONLY_ME, only applicable to publish permissions
-(void)setAudience_:(id)audience
// Requested permissions when logging in. If set, do not set publish permissions
-(void)setReadPermissions_:(id)args
{
ENSURE_SINGLE_ARG(audience, NSNumber);
FBSDKLoginButton *loginBtn = [self login];
loginBtn.defaultAudience = [audience intValue];
ENSURE_ARRAY(args);
[[self loginButton] setReadPermissions:args];
}

-(NSArray*)readPermissions
{
return [[self loginButton] readPermissions];
}

// The default is AUDIENCE_ONLY_ME, only applicable to publish permissions
-(void)setAudience_:(id)value
{
ENSURE_SINGLE_ARG(value, NSNumber);
[[self loginButton] setDefaultAudience:[TiUtils intValue:value]];
}

// The default audience to use, if publish permissions are requested at login time.
-(NSNumber*)audience
{
return [[self loginButton] defaultAudience];
}

// Sets the desired tooltip behavior
-(void)setTooltipBehavior_:(id)value
{
ENSURE_SINGLE_ARG(value, NSNumber);
[[self loginButton] setTooltipBehavior:[TiUtils intValue:value]];
}

// Gets the desired tooltip behavior
-(NSNumber*)tooltipBehavior
{
return [[self loginButton] tooltipBehavior];
}

// Sets the desired tooltip color style
-(void)setTooltipColorStyle_:(id)value
{
ENSURE_SINGLE_ARG(value, NSNumber);
[[self loginButton] setTooltipColorStyle:[TiUtils intValue:value]];
}

// Gets the desired tooltip color style
-(NSNumber*)tooltipColorStyle
{
return [[self loginButton] tooltipColorStyle];
}

@end
7 changes: 7 additions & 0 deletions ios/Classes/FacebookModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ -(id)MESSENGER_BUTTON_STYLE_WHITE_BORDERED
MAKE_SYSTEM_PROP(SHARE_DIALOG_MODE_FEED_BROWSER, FBSDKShareDialogModeFeedBrowser);
MAKE_SYSTEM_PROP(SHARE_DIALOG_MODE_FEED_WEB, FBSDKShareDialogModeFeedWeb);

MAKE_SYSTEM_PROP(LOGIN_BUTTON_TOOLTIP_BEHAVIOR_AUTOMATIC, FBSDKLoginButtonTooltipBehaviorAutomatic);
MAKE_SYSTEM_PROP(LOGIN_BUTTON_TOOLTIP_BEHAVIOR_FORCE_DISPLAY, FBSDKLoginButtonTooltipBehaviorForceDisplay);
MAKE_SYSTEM_PROP(LOGIN_BUTTON_TOOLTIP_BEHAVIOR_DISABLE, FBSDKLoginButtonTooltipBehaviorDisable);

MAKE_SYSTEM_PROP(LOGIN_BUTTON_TOOLTIP_STYLE_NEUTRAL_GRAY, FBSDKTooltipColorStyleNeutralGray);
MAKE_SYSTEM_PROP(LOGIN_BUTTON_TOOLTIP_STYLE_FRIENDLY_BLUE, FBSDKTooltipColorStyleFriendlyBlue);

/**
* JS example:
*
Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 5.2.7
version: 5.3.0
apiversion: 2
description: Allows Facebook integration for Titanium apps
author: Mark Mokryn, Ng Chee Kiat and Hans Knoechel
Expand Down
2 changes: 1 addition & 1 deletion ios/module.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

//
// How to add a Framework (example)
FRAMEWORK_SEARCH_PATHS=$(SRCROOT)/../../modules/iphone/facebook/5.2.7/platform "~/Library/Application Support/Titanium/modules/iphone/facebook/5.2.7/platform"
FRAMEWORK_SEARCH_PATHS=$(SRCROOT)/../../modules/iphone/facebook/5.3.0/platform "~/Library/Application Support/Titanium/modules/iphone/facebook/5.3.0/platform"
OTHER_LDFLAGS=$(inherited) -framework Social -framework FBSDKCoreKit -framework FBSDKLoginKit -framework FBSDKShareKit -framework FBSDKMessengerShareKit -framework Bolts
//
// OTHER_LDFLAGS=$(inherited) -framework Foo
Expand Down
2 changes: 1 addition & 1 deletion ios/titanium.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// OF YOUR TITANIUM SDK YOU'RE BUILDING FOR
//
//
TITANIUM_SDK_VERSION = 5.5.0.GA
TITANIUM_SDK_VERSION = 5.5.1.GA


//
Expand Down

0 comments on commit 9237d10

Please sign in to comment.